awema-pl / module-auth
Laravel 认证包,内置双因素认证(Authy)和社交认证(Socialite)。
v1.0.18
2020-12-23 09:22 UTC
Requires
- awema-pl/module-indigo-layout: dev-master
- guzzlehttp/guzzle: ^7.0.1
- illuminate/support: ~5|~6|~7|~8|~9
- laravel/sanctum: ^2.8
- laravel/ui: ^3.0
README
认证
Laravel 认证包,内置双因素认证(Authy)和社交认证(Socialite)。
目录
安装
通过 Composer
$ composer require awema-pl/module-auth
该包将自动注册自己。
您可以发布迁移
php artisan vendor:publish --provider="AwemaPL\Auth\AuthServiceProvider" --tag="migrations"
发布迁移后,您可以通过运行以下命令创建所需的数据库表:
php artisan migrate
发布视图
php artisan vendor:publish --provider="AwemaPL\Auth\AuthServiceProvider" --tag="views"
配置
发布配置文件
php artisan vendor:publish --provider="AwemaPL\Auth\AuthServiceProvider" --tag="config"
您可以通过取消注释来禁用附加功能
'enabled' => [ 'social', // 'two_factor', // 'email_verification', ],
添加新的 socialite 服务
'services' => [ 'github' => [ 'name' => 'GitHub' ], ... ], 'github' => [ 'client_id' => env('GITHUB_CLIENT_ID'), ... ],
并配置重定向路径
'redirects' => [ 'login' => '/twofactor', 'reset_password' => '/', ... ],
社交和双因素认证
如果配置中启用了附加模块,则需要几个 .env 变量
# SOCIALITE GITHUB GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= GITHUB_REDIRECT_URL=http://auth.test/login/github/callback # TWO FACTOR AUTHY AUTHY_SECRET=
如果启用了社交和/或双因素认证,请将相应的 traits 添加到 User 模型类中
use AwemaPL\Auth\Models\Traits\HasSocialAuthentication; use AwemaPL\Auth\Models\Traits\HasTwoFactorAuthentication; class User extends Authenticatable { use HasSocialAuthentication, HasTwoFactorAuthentication; }
邮箱验证及密码重置
要使用邮箱验证功能和密码重置,请添加 SendsEmailVerification
和 SendsPasswordReset
traits
use AwemaPL\Auth\Models\Traits\SendsPasswordReset; use AwemaPL\Auth\Models\Traits\SendsEmailVerification; class User extends Authenticatable { use SendsEmailVerification, SendsPasswordReset; }
使用方法
添加到 routes/web.php
AwemaAuth::routes();
您可以禁用注册
AwemaAuth::routes(['register' => false]);
该包将注册多个路由。
除了默认的认证路由外,它还将添加
- Socialite 路由
'login.social'
'login/{service}/callback'
- 双因素认证设置路由
'twofactor.index'
'twofactor.store'
'twofactor.destroy'
'twofactor.verify'
- 双因素认证登录路由
'login.twofactor.index'
'login.twofactor.verify'
- 邮箱验证路由
'verification.resend'
'verification.code.verify'
'verification.code'
'verification.verify'
测试
您可以使用以下命令运行测试:
composer test
贡献
有关详细信息和使用列表,请参阅 contributing.md