damirka/yii2-jwt
最新稳定版本:v0.2.1
Composer 安装命令:
composer require damirka/yii2-jwt
包简介
Trait for easier JWT integration
README 文档
README
JWT implementation for Yii2 Authorization process
For details see JWT official website.
Installation
To install (only master is available now) run:
composer require "damirka/yii2-jwt:v0.2.1"
Or add this line to require section of composer.json:
"damirka/yii2-jwt": "v0.2.1"
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 { // Use the trait in your User model use \damirka\JWT\UserTrait; // Override this method protected static function getSecretKey() { return 'someSecretKey'; } // And this one if you wish protected static function getHeaderToken() { return []; } // ... }
统计信息
- 总下载量: 84.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 67
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-03