stephenjude/filament-two-factor-authentication

Filament 双因素认证

0.0.4 2024-09-06 22:54 UTC

This package is auto-updated.

Last update: 2024-09-17 21:37:25 UTC


README

Screenshot

Filament 双因素认证 (2FA)

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

为新的和现有的 Filament 应用程序添加双因素认证。

了解更多

Filament 双因素认证

安装

以下文档将介绍如何安装此插件。如果您有任何疑问,发现错误,需要支持或提出功能请求,请随时通过stephenjudesuccess@gmail.com联系我。

您可以通过 composer 安装此包

composer require stephenjude/filament-two-factor-authentication

使用以下命令安装插件迁移

php artisan filament-two-factor-authentication:install

可选,您可以使用以下命令发布视图

php artisan vendor:publish --tag="filament-two-factor-authentication-views"

模型配置

首先,确保您的应用程序认证模型使用 TwoFactorAuthenticatable 特性

namespace App\Models;
...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticatable;

class User extends Authenticatable implements FilamentUser
{
    ...
    use TwoFactorAuthenticatable;

插件配置

通过实例化插件类并将其传递给配置中的 plugin() 方法,将双因素认证插件添加到面板中

...
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
        ])
}
...

自定义 2FA 设置页面

如果您的应用程序已经有用户资料页面,您可以将 2FA 设置添加到您的资料页面视图

<x-filament-panels::page>
    @livewire(\Stephenjude\FilamentTwoFactorAuthentication\Livewire\TwoFactorAuthentication::class)
</x-filament-panels::page>

事件

此包分发事件,您的应用程序可以订阅这些事件。您可以在 EventServiceProvider 类内部监听这些事件

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 认证

Screenshot

2FA 恢复

Screenshot

2FA 禁用

Screenshot

2FA 设置

Screenshot

2FA 启用(恢复码)

测试

composer test

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

贡献

请参阅 CONTRIBUTING 了解详情。

安全漏洞

请审查 我们的安全策略 了解如何报告安全漏洞。

致谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。