ghostzero/nova-two-factor

Nova 双因素认证

dev-nova4support 2024-04-09 13:58 UTC

This package is auto-updated.

Last update: 2024-09-09 15:21:17 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Nova-Two-Factor

Laravel nova in-dashboard 双因素认证安全功能。

更新内容

v2.2.3

  • 修复外键问题(需要运行迁移)
  • 翻译修复

v2.2.2

  • 清除当前双因素认证设置的选项

v2.2.0

  • 使用 2FA 提示 对话框重新授权任何路由。

界面

设置 2FA

screenshot

启用/禁用功能

screenshot

带有 2FA 安全性的 Nova 登录屏幕

screenshot

使用 2FA 提示重新授权任何路由

screenshot

安装包

composer require visanduma/nova-two-factor

  1. 发布配置和迁移

php artisan vendor:publish --provider="Visanduma\NovaTwoFactor\ToolServiceProvider"

根据需要更改配置


return [
    
     // enable or disable 2FA feature. default is enabled
    'enabled' => env('NOVA_TWO_FA_ENABLE',true),
    
    // name of authenticatable entity table. usually - users
    'user_table' => 'users',
    
    // Entity primary key
    'user_id_column' => 'id',
    
    // authenticatable model class
    'user_model' => \App\Models\User::class

    /* Change visibility of Nova Two Fa menu in right sidebar */
    'showin_sidebar' => true,

    'menu_text' => 'Two FA',

    'menu_icon' => 'lock-closed',

    /* Exclude any routes from 2fa security */
    'except_routes' => [
        //
    ],

    /**
     * reauthorize these urls before access, withing given timeout
     * you are allowed to use wildcards pattern for url matching
     **/

    'reauthorize_urls' => [
       // 'nova/resources/users/new',
       // 'nova/resources/users/*/edit',
    ],

    /* timeout in minutes */

    'reauthorize_timeout' => 5,

];

  1. 在配置的模型中使用 ProtectWith2FA trait
<?php

namespace App\Models;

use Visanduma\NovaTwoFactor\ProtectWith2FA;

class User extends Authenticatable{

    use ProtectWith2FA;
}

  1. 将 TwoFa 中间件添加到 nova 配置文件中
/*
    |--------------------------------------------------------------------------
    | Nova Route Middleware
    |--------------------------------------------------------------------------
    |
    | These middleware will be assigned to every Nova route, giving you the
    | chance to add your own middleware to this stack or override any of
    | the existing middleware. Or, you can just stick with this stack.
    |
    */

    'middleware' => [
        ...
        \Visanduma\NovaTwoFactor\Http\Middleware\TwoFa::class
    ],

  1. 在 Nova 服务提供者中注册 NovaTwoFactor 工具
<?php

class NovaServiceProvider extends NovaApplicationServiceProvider{

public function tools()
    {
        return [
            ...
            new \Visanduma\NovaTwoFactor\NovaTwoFactor()

        ];
    }

}


  1. 运行 php artisan migrate
  2. 完成!