Two factor authentication with Laravel and Google Authenticator

14
Two-factor Authentication With Laravel and Google Authenticator Allan Denot

Transcript of Two factor authentication with Laravel and Google Authenticator

Page 1: Two factor authentication with Laravel and Google Authenticator

Two-factor Authentication

With Laravel and Google Authenticator

Allan Denot

Page 2: Two factor authentication with Laravel and Google Authenticator

How it works

[email protected]

Login

**************

Submit

461785

Login

Submit

Two-factor Enabled

Page 3: Two factor authentication with Laravel and Google Authenticator

How it works

MyApp

[email protected]

Secret key is randomly generated

QR code is generated from secret key and

other info

User scans QR code using Google Authenticator

It starts generating time based codes or

tokens

Enabling two-factor

372631

7JASV4C4F74ZLAR6

Page 4: Two factor authentication with Laravel and Google Authenticator

How it worksVerifying code

372631

Login

Submit

Two-factor Enabled

+ = 372631 ?

372631

7JASV4C4F74ZLAR6

Page 5: Two factor authentication with Laravel and Google Authenticator

Implementation and Demo

Page 6: Two factor authentication with Laravel and Google Authenticator

Installing

composer require pragmarx/google2fa

More information at: https://github.com/antonioribeiro/google2fa

Page 7: Two factor authentication with Laravel and Google Authenticator

Routes// Generates secret key and QR image

Route::get('user/twoFactor/secret', 'UserController@twoFactorSecret');

// Enables two-factor at user profile

Route::get('user/twoFactor/enable', 'UserController@twoFactorEnable'); // code, secret

// Verify a two-factor code

Route::get('user/twoFactor/verify', 'UserController@twoFactorVerify'); // code

Page 9: Two factor authentication with Laravel and Google Authenticator

Enabling two-factor

/api/user/twoFactor/enable?secret=3UYJJUQO6O72SJJW&code=733005

Page 10: Two factor authentication with Laravel and Google Authenticator

Verifying

/api/user/twoFactor/verify?code=733005

Page 11: Two factor authentication with Laravel and Google Authenticator

Verify window// Default window is 4$valid = Google2FA::verifyKey($secret, $code);

// Setting to 0$valid = Google2FA::verifyKey($secret, $code, 0);

Page 12: Two factor authentication with Laravel and Google Authenticator

Alternatives

Page 13: Two factor authentication with Laravel and Google Authenticator

Auth as a service

https://www.authy.com/

https://auth0.com/

Page 14: Two factor authentication with Laravel and Google Authenticator

References

Google2FA: https://github.com/antonioribeiro/google2faAuthy: https://www.authy.com/Auth0: https://auth0.com/

[email protected]