<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stephenjude / filament-two-factor-authentication example snippets
namespace App\Models;
use Spatie\LaravelPasskeys\Models\Concerns\HasPasskeys;
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticatable;
//...
class User extends Authenticatable implements FilamentUser, HasPasskeys
{
use TwoFactorAuthenticatable;
//...
...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticationPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
TwoFactorAuthenticationPlugin::make()
->enableTwoFactorAuthentication() // Enable Google 2FA
->enablePasskeyAuthentication() // Enable Passkey
->addTwoFactorMenuItem() // Add 2FA menu item
->forceTwoFactorSetup() // Force 2FA setup
])
}
...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticationPlugin;
use Stephenjude\FilamentTwoFactorAuthentication\Middleware\ForceTwoFactorSetup;
use Stephenjude\FilamentTwoFactorAuthentication\Middleware\TwoFactorChallenge;
TwoFactorAuthenticationPlugin::make()
->enableTwoFactorAuthentication(
condition: true, // Enable Google 2FA
challengeMiddleware: TwoFactorChallenge::class, // Middleware to challenge user with 2FA
)
->enablePasskeyAuthentication(
condition: true, // Enable Passkey
)
->forceTwoFactorSetup(
condition: true, // Force 2FA setup for all users
use Stephenjude\FilamentTwoFactorAuthentication\Events\{RecoveryCodeReplaced,RecoveryCodesGenerated,TwoFactorAuthenticationChallenged,TwoFactorAuthenticationConfirmed,TwoFactorAuthenticationDisabled,TwoFactorAuthenticationEnabled,TwoFactorAuthenticationFailed,ValidTwoFactorAuthenticationCodeProvided};
protected $listen = [
TwoFactorAuthenticationChallenged::class => [
// Dispatched when a user is 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.
],
];