chinaphp/yii2-jwt 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chinaphp/yii2-jwt

最新稳定版本:v1.0.2

Composer 安装命令:

composer require chinaphp/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 "chinaphp/yii2-jwt:~1.0.0"

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

    "chinaphp/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 \chinaphp\JWT\UserTrait;
}

Get the jwt

<?php
// $user is an User object
$token = $user->getJwt()

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固