2017 © Pedro Peláez
 

yii2-extension yii2-jwt

Trait for easier JWT integration

image

msheng/yii2-jwt

Trait for easier JWT integration

  • Tuesday, August 9, 2016
  • by msheng
  • Repository
  • 2 Watchers
  • 7 Stars
  • 965 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 18 Forks
  • 0 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Fork from https://github.com/damirka/yii2-jwt, (*1)

yii2-jwt

JWT implementation for Yii2 Authorization process, (*2)

For details see JWT official website., (*3)

Installation

To install (only master is available now) run:, (*4)

    composer require "msheng/yii2-jwt:~1.0.0"

Or add this line to require section of composer.json:, (*5)

    "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, (*6)

project

Your project need to be an yii2-app-advanced , and here is the guide, (*7)

Set up:, (*8)

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()

The Versions

09/08 2016

dev-master

9999999-dev https://github.com/Yemsheng/yii2-jwt

Trait for easier JWT integration

  Sources   Download

MIT

The Requires

 

jwt yii

09/08 2016

1.0.1

1.0.1.0 https://github.com/Yemsheng/yii2-jwt

Trait for easier JWT integration

  Sources   Download

MIT

The Requires

 

jwt yii

09/08 2016

dev-develop

dev-develop https://github.com/Yemsheng/yii2-jwt

Trait for easier JWT integration

  Sources   Download

MIT

The Requires

 

jwt yii

04/08 2016

1.0.0

1.0.0.0 https://github.com/Yemsheng/yii2-jwt

Trait for easier JWT integration

  Sources   Download

MIT

The Requires

 

jwt yii

10/04 2016

v0.1.0

0.1.0.0 https://github.com/damirka/yii2-jwt

Trait for easier JWT integration

  Sources   Download

MIT

The Requires

 

jwt yii

09/11 2015

0.0.0

0.0.0.0 https://github.com/damirka/yii2-jwt

Set of classes for easier JWT integration

  Sources   Download

MIT

The Requires

 

jwt yii auth0