wearesho-team / yii2-authentication
Yii2 认证集成
1.3.3
2023-12-07 13:48 UTC
Requires
- php: >=7.4
- horat1us/yii2-migration-bootstrap: ^1.3
- wearesho-team/token-generator: ^1.2
- wearesho-team/yii-http: ^1.14
- wearesho-team/yii2-authorization: ^1.3 | ^2.0
- wearesho-team/yii2-tokens: ^1.1
- yiisoft/yii2: ^2.0.47
Requires (Dev)
- horat1us/yii2-asset-free: ^1.0
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
README
一个简单的Yii2库,用于认证API用户并使用wearesho-team/yii2-authorization生成授权令牌
安装
使用composer
composer require wearesho-team/yii2-authentication:^1.0
用法
首先,您需要实现IdentityInterface。然后,您可以在应用程序中使用Controller。
配置
<?php // config.php use Wearesho\Yii2\Authentication; use Wearesho\Yii2\Authorization; return [ 'controllerMap' => [ 'auth' => [ 'class' => Authentication\Controller::class, 'identityClass' => YourIdentityClass::class, 'repository' => Authorization\Repository::class, ], ], ];
HTTP 路由
控制器中只声明了一个操作:index。它可以使用不同的HTTP方法调用。以下是对控制器中每个操作的描述。
基本控制器
POST
尝试使用提供的凭据登录
- 请求体参数
{ "LoginForm": { "login": "login value", "password": "password value" } }
- 响应 202 - 当凭据正确且已创建访问令牌时
{ "id": "returned user id, integer value", "access": "access token", "refresh": "refresh token" }
- 响应 400 - 当您提供了无效的登录/密码或其中之一为空时
{ "errors": [ { "attribute": "login", "details": "Login is required" }, { "attribute": "password", "details": "password is invalid." } ] }
DELETE
注销操作
- 查询参数
?refresh=*refresh token value*
- 响应 205 - 当令牌成功删除时
[]
- 响应 400 - 当传递的令牌无效或为空时
{ "errors": [ { "attribute": "refresh", "details": "Refresh is required" } ] }
PUT
此操作解释令牌刷新。当前访问令牌将被删除,将创建新令牌并返回。
- 查询参数
?refresh=*refresh token value*
- 响应 205 - 当前令牌正在删除,并创建新令牌
{ "id": "returned user id, integer value", "access": "access token", "refresh": "refresh token" }
- 响应 400 - 当传递的令牌无效或为空时
{ "errors": [ { "attribute": "refresh", "details": "Refresh is required" } ] }
双因素认证
此库还包括双因素认证的实现。