wilianto/yii2-jwt

Set of classes for easier JWT integration

Installs: 117

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 20

Type:yii2-extension

0.0.0 2015-11-09 07:42 UTC

This package is not auto-updated.

Last update: 2024-11-13 18:54:38 UTC


README

JWT implementation for Yii2 Authorization process

Installation

To install (only master is available now) run:

    composer require "wilianto/yii2-jwt"

Or add this line to require section of composer.json:

    "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

Set up:

In controller:

<?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:

<?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;

    // ...
}