https://github.com/stephenjude/filament-two-factor-authentication
Add two factor authentication (2FA) to Filament panels.
https://github.com/stephenjude/filament-two-factor-authentication
2fa filamentphp laravel php two-factor-authentication
Last synced: about 1 year ago
JSON representation
Add two factor authentication (2FA) to Filament panels.
- Host: GitHub
- URL: https://github.com/stephenjude/filament-two-factor-authentication
- Owner: stephenjude
- License: mit
- Created: 2024-08-13T13:48:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-12T19:01:27.000Z (over 1 year ago)
- Last Synced: 2025-03-28T08:24:18.346Z (about 1 year ago)
- Topics: 2fa, filamentphp, laravel, php, two-factor-authentication
- Language: PHP
- Homepage:
- Size: 425 KB
- Stars: 52
- Watchers: 3
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README

# Filament Two Factor Authentication (2FA)
[](https://packagist.org/packages/stephenjude/filament-two-factor-authentication)
[](https://github.com/stephenjude/filament-two-factor-authentication/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/stephenjude/filament-two-factor-authentication/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain)
[](https://packagist.org/packages/stephenjude/filament-two-factor-authentication)
Add two factor authentication to new and existing Filament applications.
## Learn More
[Filament Two-Factor Authentication Demo](https://www.youtube.com/watch?v=zLqKFsAmEaQ) — Filament Daily
## Installation
Below, you'll find documentation on installing this plugin. If you have any questions, find a bug, need support, or have
a feature request, please don't hesitate to reach out to me at stephenjudesuccess@gmail.com.
You can install the package via composer:
```bash
composer require stephenjude/filament-two-factor-authentication
```
Install the plugin migration using:
```bash
php artisan filament-two-factor-authentication:install
```
Optionally, you can publish the views using
```bash
php artisan vendor:publish --tag="filament-two-factor-authentication-views"
```
## Model Configuration
First, ensure that your application's authenticatio model uses the `TwoFactorAuthenticatable` trait:
```php
namespace App\Models;
...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticatable;
class User extends Authenticatable implements FilamentUser
{
...
use TwoFactorAuthenticatable;
```
## Plugin Configuration
Add two factor authentication plugin to a panel by instantiating the plugin class and passing it to the plugin() method
of the configuration:
```php
...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticationPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
TwoFactorAuthenticationPlugin::make()
->addTwoFactorMenuItem() // Add 2FA settings to user menu items
->enforceTwoFactorSetup() // Enforce 2FA setup for all users
])
}
...
```
### Custom 2FA Settings Page
If your application already has a user profile page, you can add a 2FA settings to your profile page view:
```php
@livewire(\Stephenjude\FilamentTwoFactorAuthentication\Livewire\TwoFactorAuthentication::class)
```
## Events
This package dispatches events which your application can subscribe to. You can listen to these events inside your EventServiceProvider class:
```php
use Stephenjude\FilamentTwoFactorAuthentication\Events\{RecoveryCodeReplaced,RecoveryCodesGenerated,TwoFactorAuthenticationChallenged,TwoFactorAuthenticationConfirmed,TwoFactorAuthenticationDisabled,TwoFactorAuthenticationEnabled,TwoFactorAuthenticationFailed,ValidTwoFactorAuthenticationCodeProvided};
protected $listen = [
TwoFactorAuthenticationChallenged::class => [
// Dispatched when a user is required to enter 2FA code during login.
],
TwoFactorAuthenticationFailed::class => [
// Dispatched when a user provides incorrect 2FA code or recovery code during login.
],
ValidTwoFactorAuthenticationCodeProvided::class => [
// Dispatched when a user provides a valid 2FA code during login.
]
TwoFactorAuthenticationConfirmed::class => [
// Dispatched when a user confirms code during 2FA setup.
],
TwoFactorAuthenticationEnabled::class => [
// Dispatched when a user enables 2FA.
],
TwoFactorAuthenticationDisabled::class => [
// Dispatched when a user disables 2FA.
],
RecoveryCodeReplaced::class => [
// Dispatched after a user's recovery code is replaced.
],
RecoveryCodesGenerated::class => [
// Dispatched after a user's recovery codes are generated.
],
];
```
## Screenshot

#### 2FA Authentication

#### 2FA Recovery

#### 2FA Disabled

#### 2FA Setup

#### 2FA Enabled (Recovery Codes)
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [stephenjude](https://github.com/stephenjude)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.