msheng/yii2-jwt
最新稳定版本:1.0.1
Composer 安装命令:
composer require msheng/yii2-jwt
包简介
Trait for easier JWT integration
README 文档
README
Fork from https://github.com/damirka/yii2-jwt
yii2-jwt
JWT implementation for Yii2 Authorization process
For details see JWT official website.
Installation
To install (only master is available now) run:
composer require "msheng/yii2-jwt:~1.0.0"
Or add this line to require section of composer.json:
"msheng/yii2-jwt": "~1.0.0"
Usage
There is only one trait - UserTrait - which gives you 5 methods for authorization and JWT-management in User model
project
Your project need to be an yii2-app-advanced , and here is the guide
Set up:
In common/config/params.php
<?php $params = [ 'JWT_SECRET' => 'your_secret', 'JWT_EXPIRE' => 10*24*60*60 ]
In controller:
<?php // ... use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; class BearerAuthController extends \yii\rest\ActiveController { public function behaviors() { return array_merge(parent::behaviors(), [ 'authenticator' => [ 'class' => CompositeAuth::className(), 'authMethods' => [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 \msheng\JWT\UserTrait; }
Get the jwt
<?php // $user is an User object $token = $user->getJwt()
统计信息
- 总下载量: 5.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-04