https://github.com/sicaboy/laravel-mfa
Laravel 2FA / Multi-factor Authentication
https://github.com/sicaboy/laravel-mfa
2fa factor-authentication laravel mfa middleware
Last synced: about 1 year ago
JSON representation
Laravel 2FA / Multi-factor Authentication
- Host: GitHub
- URL: https://github.com/sicaboy/laravel-mfa
- Owner: sicaboy
- License: mit
- Created: 2020-04-12T13:08:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T19:53:29.000Z (almost 3 years ago)
- Last Synced: 2025-03-26T02:42:41.362Z (about 1 year ago)
- Topics: 2fa, factor-authentication, laravel, mfa, middleware
- Language: PHP
- Homepage:
- Size: 140 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Multi-factor Authentication (MFA) / Two-factor Authentication (2FA)
[](https://packagist.org/packages/sicaboy/laravel-mfa)
[](LICENSE.md)
[](https://packagist.org/packages/sicaboy/laravel-mfa)
## Introduction
This package was a part of [sicaboy/laravel-security](https://github.com/sicaboy/laravel-security). Later moved to this separated repository.
This package provides a Middleware to protect pages with MFA in your Laravel projects.
## Installation
Requirements:
- [PHP](https://php.net) 5.5+, 7.*, 8.0+
- [Composer](https://getcomposer.org)
To get the latest version of Laravel MFA, simply run:
```
composer require sicaboy/laravel-mfa
```
Then do vendor publish:
```
php artisan vendor:publish --provider="Sicaboy\LaravelMFA\LaravelMFAServiceProvider"
```
After publishing, you can modify templates and config in:
```
app/config/laravel-mfa.php
resources/views/vendor/laravel-mfa/
```
If you're on Laravel < 5.5, you'll need to register the service provider. Open up `config/app.php` and add the following to the `providers` array:
```php
Siaboy\LaravelMFA\LaravelMFAServiceProvider::class,
```
# Usage
### General Usage
Attach the middleware to your routes to protect your pages.
```php
Route::middleware(['mfa'])->group(function () {
...
});
```
### If Using Different Auth Objects
If you use different `Auth` objects, for example user auth and admin auth, you can apply following to enable MFA for admin pages.
- Attach the middleware to your routes.
```php
Route::middleware(['mfa:admin'])->group(function () {
...
});
```
- Add a group in your config file `config/laravel-mfa.php`
```php
return [
'default' => [
...
],
'group'
'admin' => [ // Example, when using middleware 'mfa:admin'. Attributes not mentioned will be inherit from `default` above
'login_route' => 'admin.login',
'auth_user_closure' => function() {
return \Encore\Admin\Facades\Admin::user();
},
],
'other_name' => [ // Middleware 'mfa:other_name'
...
]
],
```
## Queue
If your application has a `artisan queue:work` daemon running, you can send auth code in a queue by changing the config.
```php
return [
'default' => [
...
'email' => [
'queue' => true,
...
]
]
]
```
## TODO
- Switch on MFA on specific users (DB field-based)
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.