This extension provides the JWT integration for Yii 2 framework.
This is fork of sizeg/yii2-jwt package
Add the package to your composer.json
:
{
"require": {
"bizley/jwt": "^2.0"
}
}
and run composer update
or alternatively run composer require bizley/jwt:^2.0
Add jwt
component to your configuration file:
[
'components' => [
'jwt' => [
'class' => \bizley\jwt\Jwt::class,
'key' => ... // Secret key string or path to the public key file
],
],
],
Now you have got access to JWT library through Yii::$app->jwt
and some helper methods like getBuilder()
,
getParser()
, and getValidationData()
. You can validate your JSON Web Token by using validateToken()
method and
check its signature with verifyToken()
.
Configure the authenticator
behavior in controller.
class ExampleController extends Controller
{
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => \bizley\jwt\JwtHttpBearerAuth::class,
];
return $behaviors;
}
}
For other configuration options refer to the Yii 2 Guide.
Please refer to the lcobucci/jwt Documentation.