stickee / laravel-2fa
Stickee Laravel 2FA - add two factor authentication
Installs: 1 209
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 1
Requires
- php: ^7.2.0|^8.0
- bacon/bacon-qr-code: ^2.0
- illuminate/contracts: ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- pragmarx/google2fa: ^7.0
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0|^5.0
- phpunit/phpunit: ^8.0|^9.0|^10.0
README
This a composer module for adding two factor authentication.
Contents
Quick Start
composer require stickee/laravel-2fa
php artisan migrate
2FA is now enabled, but not enforced. To enforce it for all users, set in your .env
:
LARAVEL_2FA_REQUIRED=true
Users will be prompted to enroll in 2FA when they log in.
Installation
composer require stickee/laravel-2fa
This module ships with a Laravel service provider which will be automatically registered for Laravel 5.5+.
Manual registration
The module can be manually registered by adding this to the providers
array in config/app.php
:
Stickee\Laravel2fa\ServiceProvider::class,
Configuration
Environment Variables
Config File
Publish the configuration file to your project with this command:
php artisan vendor:publish --provider=Stickee\\Laravel2fa\\ServiceProvider --tag=config
Customisation
The package is highly customisable - most parts can be swapped out for your own implementation if required.
How Do I...?
- Change the templates
- Publish the views to your project with
php artisan vendor:publish --provider=Stickee\\Laravel2fa\\ServiceProvider --tag=laravel-views
and edit them there.
- Publish the views to your project with
- Customise the text / add a translation
- Publish the translations to your project with
php artisan vendor:publish --provider=Stickee\\Laravel2fa\\ServiceProvider --tag=translations
and edit them there.
- Publish the translations to your project with
- Change the QR code generator
- To change to one of the built-in BaconQrCode backends, change the config variable
qr_code_generator
. At the time of writing, supported backends are\BaconQrCode\Renderer\Image\ImagickImageBackEnd::class
\BaconQrCode\Renderer\Image\SvgImageBackEnd::class
\BaconQrCode\Renderer\Image\EpsImageBackEnd::class
- To use something completely different, create a class implementing
\Stickee\Laravel2fa\Contracts\QrCodeGenerator
and bind it to that interface in your service provider
- To change to one of the built-in BaconQrCode backends, change the config variable
- Create a custom driver / provider
- Implement
\Stickee\Laravel2fa\Contracts\Driver
and register it in yourlaravel-2fa.drivers
config. To make things easier you can probably extend\Stickee\Laravel2fa\Drivers\AbstractDriver
.
- Implement
Developing
The easiest way to make changes is to make the project you're importing the module in to load the module from your filesystem instead of the composer repository, like this:
composer remove stickee/laravel-2fa
- Edit
composer.json
and add
where "../laravel-2fa" is the path to where you have this project checked out"repositories": [ { "type": "path", "url": "../laravel-2fa" } ]
composer require stickee/laravel-2fa
NOTE: Do not check in your composer.json
like this!