awes-io / auth
Laravel 认证包,内置双因素(Authy)认证和社交认证(Socialite)。
v1.2.0
2019-10-10 17:18 UTC
Requires
- guzzlehttp/guzzle: ^6.3
- illuminate/support: ~5|~6
- laravel/socialite: ^4.0
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~7.0
- sempro/phpunit-pretty-print: ^1.0
README
认证
Laravel 认证包,内置双因素(Authy)认证和社交认证(Socialite)。
目录
安装
通过 Composer
$ composer require awes-io/auth
包将自动注册自己。
您可以通过发布迁移来创建所需的数据库表。
php artisan vendor:publish --provider="AwesIO\Auth\AuthServiceProvider" --tag="migrations"
在发布迁移后,您可以通过运行以下命令创建所需的数据库表:
php artisan migrate
发布视图
php artisan vendor:publish --provider="AwesIO\Auth\AuthServiceProvider" --tag="views"
配置
发布配置文件
php artisan vendor:publish --provider="AwesIO\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=
如果启用了社交和/或双因素认证,请将相应的特性添加到 User 模型类中
use AwesIO\Auth\Models\Traits\HasSocialAuthentication; use AwesIO\Auth\Models\Traits\HasTwoFactorAuthentication; class User extends Authenticatable { use HasSocialAuthentication, HasTwoFactorAuthentication; }
电子邮件验证和重置密码
要使用电子邮件验证功能和重置密码,请添加 SendsEmailVerification
和 SendsPasswordReset
特性
use AwesIO\Auth\Models\Traits\SendsPasswordReset; use AwesIO\Auth\Models\Traits\SendsEmailVerification; class User extends Authenticatable { use SendsEmailVerification, SendsPasswordReset; }
使用方法
添加到 routes/web.php
AwesAuth::routes();
您可以禁用注册
AwesAuth::routes(['register' => false]);
包将注册多个路由。
除了默认的认证路由外,它还将添加
- 社交路由
'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