wilianto/yii2-jwt

用于简化JWT集成的类集

安装: 117

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 20

类型:yii2-extension

0.0.0 2015-11-09 07:42 UTC

This package is not auto-updated.

Last update: 2024-09-18 18:09:55 UTC


README

为Yii2授权过程实现的JWT实现

安装

要安装(目前只有master版本可用),请运行

    composer require "wilianto/yii2-jwt"

或将此行添加到composer.json的require部分

    "wilianto/yii2-jwt": "dev-master"

用法

只有一个特质 - UserTrait - 它为用户模型提供5个用于授权和JWT管理的函数

设置

在控制器中

<?php

// ...

use yii\filters\auth\HttpBearerAuth;

class BearerAuthController extends \yii\rest\ActiveController
{
    public function behaviors()
    {
        return array_merge(parent::behaviors(), [
            'bearerAuth' => [
                'class' => HttpBearerAuth::className()
            ]
        ]);
    }
}

在用户模型中

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

    // ...
}