yiisoft/auth-jwt
最新稳定版本:2.1.0
Composer 安装命令:
composer require yiisoft/auth-jwt
包简介
Yii auth JWT method
关键字:
README 文档
README
Yii Auth JWT
The package provides JWT authentication method for Yii Auth.
Requirements
- PHP 8.1 or higher.
Installation
The package could be installed with Composer:
composer require yiisoft/auth-jwt
General usage
Configuring within Yii
-
Set JWT parameters in your
params.phpconfig file:'yiisoft/auth-jwt' => [ 'algorithms' => [ // your signature algorithms ], 'serializers' => [ // your token serializers ], 'key' => [ 'secret' => 'your-secret', 'file' => 'your-certificate-file', ], ],
-
Setup definitions, required for
\Yiisoft\Auth\Middleware\Authenticationmiddleware in a config, for example, inconfig/web/auth.php:/** @var array $params */ use Yiisoft\Auth\Jwt\TokenManagerInterface; use Yiisoft\Auth\Jwt\TokenManager; use Yiisoft\Auth\AuthenticationMethodInterface; use Yiisoft\Auth\Jwt\JwtMethod; return [ KeyFactoryInterface::class => [ 'class' => FromSecret::class, '__construct()' => [ $params['yiisoft/auth-jwt']['key']['secret'] ], ], AuthenticationMethodInterface::class => JwtMethod::class, ];
Note: Don't forget to declare your implementations of
\Yiisoft\Auth\IdentityInterfaceand\Yiisoft\Auth\IdentityRepositoryInterface. -
Use
Yiisoft\Auth\Middleware\Authenticationmiddleware. Read more about middlewares in the middleware guide.
Configuring independently
You can configure Authentication middleware manually:
/** @var \Yiisoft\Auth\IdentityRepositoryInterface $identityRepository */ $identityRepository = getIdentityRepository(); $tokenRepository = $container->get(\Yiisoft\Auth\Jwt\TokenRepositoryInterface::class); $authenticationMethod = new \Yiisoft\Auth\Jwt\JwtMethod($identityRepository, $tokenRepository); $middleware = new \Yiisoft\Auth\Middleware\Authentication( $authenticationMethod, $responseFactory, // PSR-17 ResponseFactoryInterface. $failureHandler // Optional, \Yiisoft\Auth\Handler\AuthenticationFailureHandler by default. );
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Auth JWT is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
Support the project
Follow updates
统计信息
- 总下载量: 4.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-09-29