{"id":15525152,"url":"https://github.com/antonioribeiro/google2fa-laravel","last_synced_at":"2025-05-13T15:13:12.078Z","repository":{"id":38238230,"uuid":"94630851","full_name":"antonioribeiro/google2fa-laravel","owner":"antonioribeiro","description":"A One Time Password Authentication package, compatible with Google Authenticator for Laravel","archived":false,"fork":false,"pushed_at":"2025-02-26T19:42:31.000Z","size":264,"stargazers_count":976,"open_issues_count":57,"forks_count":187,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-23T21:44:08.023Z","etag":null,"topics":["2fa","app-security","authentication","laravel","php","two-factor-authentication"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonioribeiro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-17T15:04:32.000Z","updated_at":"2025-04-21T16:45:09.000Z","dependencies_parsed_at":"2024-06-18T10:44:09.911Z","dependency_job_id":"719793a9-ac4c-479b-afce-52371bb135cf","html_url":"https://github.com/antonioribeiro/google2fa-laravel","commit_stats":{"total_commits":180,"total_committers":35,"mean_commits":5.142857142857143,"dds":"0.36111111111111116","last_synced_commit":"0c3f5ee764d86fbb0af9f662d6ab927162199fc1"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fgoogle2fa-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fgoogle2fa-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fgoogle2fa-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fgoogle2fa-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonioribeiro","download_url":"https://codeload.github.com/antonioribeiro/google2fa-laravel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969266,"owners_count":21992264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2fa","app-security","authentication","laravel","php","two-factor-authentication"],"created_at":"2024-10-02T10:55:09.402Z","updated_at":"2025-05-13T15:13:07.065Z","avatar_url":"https://github.com/antonioribeiro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google2FA for Laravel\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/pragmarx/google2fa-laravel\"\u003e\u003cimg alt=\"Latest Stable Version\" src=\"https://img.shields.io/packagist/v/pragmarx/google2fa-laravel.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://scrutinizer-ci.com/g/antonioribeiro/google2fa-laravel/?branch=master\"\u003e\u003cimg alt=\"Code Quality\" src=\"https://img.shields.io/scrutinizer/g/antonioribeiro/google2fa-laravel.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://travis-ci.org/antonioribeiro/google2fa-laravel\"\u003e\u003cimg alt=\"Build\" src=\"https://img.shields.io/travis/antonioribeiro/google2fa-laravel.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/pragmarx/google2fa-laravel\"\u003e\u003cimg alt=\"Downloads\" src=\"https://img.shields.io/packagist/dt/pragmarx/google2fa-laravel.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://scrutinizer-ci.com/g/antonioribeiro/google2fa-laravel/?branch=master\"\u003e\u003cimg alt=\"Coverage\" src=\"https://img.shields.io/scrutinizer/coverage/g/antonioribeiro/google2fa-laravel.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://styleci.io/repos/94630851\"\u003e\u003cimg alt=\"StyleCI\" src=\"https://styleci.io/repos/94630851/shield\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://travis-ci.org/antonioribeiro/google2fa-laravel\"\u003e\u003cimg alt=\"PHP\" src=\"https://img.shields.io/badge/PHP-7.0%20--%208.0-brightgreen.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n### Google Two-Factor Authentication Package for Laravel\n\nGoogle2FA is a PHP implementation of the Google Two-Factor Authentication Module, supporting the HMAC-Based One-time Password (HOTP) algorithm specified in [RFC 4226](https://tools.ietf.org/html/rfc4226) and the Time-based One-time Password (TOTP) algorithm specified in [RFC 6238](https://tools.ietf.org/html/rfc6238).\n\nThis package is a Laravel bridge to [Google2FA](https://github.com/antonioribeiro/google2fa)'s PHP package.\n\nThe intent of this package is to create QRCodes for Google2FA and check user typed codes. If you need to create backup/recovery codes, please check below.\n\n### Recovery/Backup codes\n\nif you need to create recovery or backup codes to provide a way for your users to recover a lost account, you can use the [Recovery Package](https://github.com/antonioribeiro/recovery). \n\n## Demos, Example \u0026 Playground\n\nPlease check the [Google2FA Package Playground](https://pragmarx.com/playground/google2fa#/).\n\n![playground](https://github.com/antonioribeiro/google2fa/raw/master/docs/playground.jpg)\n\nHere's an demo app showing how to use Google2FA: [google2fa-example](https://github.com/antonioribeiro/google2fa-example).\n\nYou can scan the QR code on [this (old) demo page](https://antoniocarlosribeiro.com/technology/google2fa) with a Google Authenticator app and view the code changing (almost) in real time.\n\n## Compatibility\n\n| Laravel | [Google2FA](https://github.com/antonioribeiro/google2fa) | Google2FA-Laravel |\n|---------|-----------|-------------------|\n| 4.2     | \u003c= 1.0.1  |                   |\n| 5.0-5.1 | \u003c= 1.0.1  |                   |\n| 5.2-10.x | \u003e= 2.0.0  | \u003e= 0.2.0          |\n\nBefore Google2FA 2.0 (Laravel 5.1) you have to install `pragmarx/google2fa:~1.0`, because this package was both a Laravel package and a PHP (agnostic).   \n\n## Demo\n\nClick [here](https://pragmarx.com/playground/google2fa/middleware) to see the middleware demo:\n\n![middleware](docs/middleware.jpg)\n\n## Installing\n\nUse Composer to install it:\n\n    composer require pragmarx/google2fa-laravel\n\n\n## Installing on Laravel\n\n### Laravel 5.5 and above\n\nYou don't have to do anything else, this package autoloads the Service Provider and create the Alias, using the new Auto-Discovery feature.\n\n### Laravel 5.4 and below\n\nAdd the Service Provider and Facade alias to your `app/config/app.php` (Laravel 4.x) or `config/app.php` (Laravel 5.x):\n\n``` php\nPragmaRX\\Google2FALaravel\\ServiceProvider::class,\n\n'Google2FA' =\u003e PragmaRX\\Google2FALaravel\\Facade::class,\n```\n\n## Publish the config file\n\n``` php\nphp artisan vendor:publish --provider=\"PragmaRX\\Google2FALaravel\\ServiceProvider\"\n```\n\n## Using It\n\n#### Use the Facade\n\n``` php\nuse Google2FA;\n\nreturn Google2FA::generateSecretKey();\n```\n\n#### In Laravel you can use the IoC Container\n\n``` php\n$google2fa = app('pragmarx.google2fa');\n\nreturn $google2fa-\u003egenerateSecretKey();\n```\n\n## Middleware\n\nThis package has a middleware which will help you code 2FA on your app. To use it, you just have to:\n\n### Add the middleware to your Kernel.php:\n\n``` php\nprotected $routeMiddleware = [\n    ...\n    '2fa' =\u003e \\PragmaRX\\Google2FALaravel\\Middleware::class,\n];\n```\n\n### Using it in one or more routes:\n\n``` php\nRoute::get('/admin', function () {\n    return view('admin.index');\n})-\u003emiddleware(['auth', '2fa']);\n```\n\n### QRCode\n\nThis package uses the [Google2FA-QRCode package](https://github.com/antonioribeiro/google2fa-qrcode), please check it for more info on how to configure the proper QRCode generators for your use case.\n\n### Imagick QRCode Backend\n\nThere are three available: **imagemagick** (default), **svg** and **eps**. \n\nYou can change it via config:\n\n``` php\n/*\n * Which image backend to use for generating QR codes?\n *\n * Supports imagemagick, svg and eps\n */\n'qrcode_image_backend' =\u003e \\PragmaRX\\Google2FALaravel\\Support\\Constants::QRCODE_IMAGE_BACKEND_IMAGEMAGICK,\n```\n \nOr runtime:\n\n``` php\nGoogle2FA::setQRCodeBackend('svg');\n```\n\n### Configuring the view\n\nYou can set your 'ask for a one time password' view in the config file (config/google2fa.php):\n\n``` php\n/**\n * One Time Password View\n */\n'view' =\u003e 'google2fa.index',\n```\n\nAnd in the view you just have to provide a form containing the input, which is also configurable:\n\n``` php\n/**\n * One Time Password request input name\n */\n'otp_input' =\u003e 'one_time_password',\n```\n\nHere's a form example:\n\n```html\n    \u003cform action=\"/google2fa/authenticate\" method=\"POST\"\u003e\n        \u003cinput name=\"one_time_password\" type=\"text\"\u003e\n\n        \u003cbutton type=\"submit\"\u003eAuthenticate\u003c/button\u003e\n    \u003c/form\u003e\n```\n\n## One Time Password Lifetime\n\nUsually an OTP lasts forever, until the user logs off your app, but, to improve application safety, you may want to re-ask, only for the Google OTP, from time to time. So you can set a number of minutes here:\n\n``` php\n/**\n* Lifetime in minutes.\n* In case you need your users to be asked for a new one time passwords from time to time.\n*/\n\n'lifetime' =\u003e 0, // 0 = eternal\n```\nKeep in mind that this uses the Laravel sessions in the background. If this number exceeds the value set in ``config('session.lifetime')`` you will still be logged out, even if your OTP lifetime has not expired.\n\nAnd you can decide whether your OTP will be kept alive while your users are browsing the site or not:\n\n``` php\n/**\n * Renew lifetime at every new request.\n */\n\n'keep_alive' =\u003e true,\n```\n\n## Manually logging out from 2Fa\n\nThis command will logout your user and redirect he/she to the 2FA form on the next request:\n\n``` php\nGoogle2FA::logout();\n```\n\nIf you don't want to use the Facade, you may:\n\n``` php\nuse PragmaRX\\Google2FALaravel\\Support\\Authenticator;\n\n(new Authenticator(request()))-\u003elogout();\n```\n\n## Throttling / Lockout after X attempts\n\nUnless you need something really fancy, you can probably use Laravel's [route throttle middleware](https://laravel.com/docs/6.x/middleware) for that:\n \n```php\nRoute::get('/admin', function () {\n    return view('admin.index');\n})-\u003emiddleware(['auth', '2fa', 'throttle']);\n```\n\n## Stateless usage\n\n```php\n$authenticator = app(Authenticator::class)-\u003ebootStateless($request);\n\nif ($authenticator-\u003eisAuthenticated()) {\n    // otp auth success!\n}\n```\n\nYou can also use a stateless middleware: \n\n``` php\nprotected $routeMiddleware = [\n    ...\n    '2fa' =\u003e \\PragmaRX\\Google2FALaravel\\MiddlewareStateless::class,\n];\n```\n\n## 2FA and Laravel login via remember \n\nWhen Laravel login via remember is activated, the session is renovated and the 2FA code is required again. To solve this, add the ``LoginViaRemember`` listener in your ``App\\Providers\\EventServiceProvider``:\n\n``` php\nuse Illuminate\\Auth\\Events\\Login;\nuse PragmaRX\\Google2FALaravel\\Listeners\\LoginViaRemember;\n\nclass EventServiceProvider extends ServiceProvider\n{\n    protected $listen = [\n        Login::class =\u003e [\n            LoginViaRemember::class,\n        ],\n    ];\n...\n```\n\n## Events\n\nThe following events are fired:\n\n- EmptyOneTimePasswordReceived\n- LoggedOut\n- LoginFailed\n- LoginSucceeded\n- OneTimePasswordExpired\n- OneTimePasswordRequested\n\n## Documentation\n\nCheck the ReadMe file in the main [Google2FA](https://github.com/antonioribeiro/google2fa) repository.\n\n## Tests\n\nThe package tests were written with [phpspec](http://www.phpspec.net/en/latest/).\n\n## Author\n\n[Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)\n\n## License\n\nGoogle2FA is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\n## Contributing\n\nPull requests and issues are more than welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioribeiro%2Fgoogle2fa-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonioribeiro%2Fgoogle2fa-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioribeiro%2Fgoogle2fa-laravel/lists"}