aracoool/yii2-jwt

JWT for Yii2

v0.3 2017-08-03 13:26 UTC

This package is auto-updated.

Last update: 2024-10-29 04:53:19 UTC


README

JWT implementation for Yii2 Authorization process

For details see JWT official website.

Installation

To install (only master is available now) run:

    composer require aracoool/yii2-jwt

Usage

Configured components

...
'jwt' => [
    'class' => JsonWebToken::class,
    'jwtKey' => 'key_for_signature'
],
'user' => [
    'class' => \JWT\User::class,
    'identityClass' => \app\models\User::class,
    'enableAutoLogin' => true,
],
...

Usage of component

Encode data

\Yii::$app->jwt->encode([
    'name' => 'Username'
]);

Decode hash

\Yii::$app->jwt->decode('jwt.hash.string');

Configure controller

...
'authenticator' => [
    'class' => \JWT\HttpJwtAuth::class,
    'except' => ['login', 'error']
]
...