yii2-jwt
JWT implementation for Yii2 Authorization process, (*1)
Installation
To install (only master is available now) run:, (*2)
composer require "wilianto/yii2-jwt"
Or add this line to require section of composer.json:, (*3)
"wilianto/yii2-jwt": "dev-master"
Usage
There is only one trait - UserTrait - which gives you 5 methods for
authorization and JWT-management in User model, (*4)
Set up:, (*5)
In controller:, (*6)
<?php
// ...
use yii\filters\auth\HttpBearerAuth;
class BearerAuthController extends \yii\rest\ActiveController
{
public function behaviors()
{
return array_merge(parent::behaviors(), [
'bearerAuth' => [
'class' => HttpBearerAuth::className()
]
]);
}
}
In User model:, (*7)
<?php
// ...
use yii\db\ActiveRecord;
use yii\web\IdentityInterface
class User extends ActiveRecord implements IdentityInterface
{
// Just use trait in User model, implement two abstract methods and that's
// all you've got to do
use \wilianto\JWT\UserTrait;
// ...
}