two factor authentication with laravel and google authenticator
TRANSCRIPT
![Page 1: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/1.jpg)
Two-factor Authentication
With Laravel and Google Authenticator
Allan Denot
![Page 3: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/3.jpg)
How it works
MyApp
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](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/4.jpg)
How it worksVerifying code
372631
Login
Submit
Two-factor Enabled
+ = 372631 ?
372631
7JASV4C4F74ZLAR6
![Page 5: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/5.jpg)
Implementation and Demo
![Page 6: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/6.jpg)
Installing
composer require pragmarx/google2fa
More information at: https://github.com/antonioribeiro/google2fa
![Page 7: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/7.jpg)
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 8: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/8.jpg)
{"two_factor_secret": "3UYJJUQO6O72SJJW","two_factor_qr": "https://chart.googleapis.com/chart?
chs=200x200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FSpikeNode%3Aadenot%40gmail.com%3Fsecret%3D7JASV4C4F74ZLAR6%26issuer%3DSpikeNode"}
Generating Secret and QR/api/user/twoFactor/secret
![Page 9: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/9.jpg)
Enabling two-factor
/api/user/twoFactor/enable?secret=3UYJJUQO6O72SJJW&code=733005
![Page 10: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/10.jpg)
Verifying
/api/user/twoFactor/verify?code=733005
![Page 11: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/11.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/12.jpg)
Alternatives
![Page 13: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/13.jpg)
Auth as a service
https://www.authy.com/
https://auth0.com/
![Page 14: Two factor authentication with Laravel and Google Authenticator](https://reader035.vdocument.in/reader035/viewer/2022071701/55cb94a9bb61ebd8528b480a/html5/thumbnails/14.jpg)
References
Google2FA: https://github.com/antonioribeiro/google2faAuthy: https://www.authy.com/Auth0: https://auth0.com/