2017 © Pedro Peláez
 

cakephp-component cakephp-jwt-claims

CakePHP plugin for read claims on jwt token

image

ramosisw/cakephp-jwt-claims

CakePHP plugin for read claims on jwt token

  • Friday, May 4, 2018
  • by ramosisw
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

cakephp-jwt-claims

Build Status Coverage Total Downloads License, (*1)

CakePHP 3.6+ Component to read claims of JWT on Authorization, (*2)

Installation

composer require ramosisw/cakephp-jwt-claims

Configuration:

Setup ClaimsComponent:, (*3)


// In your controller, for e.g. src/Controller/AppController.php public function initialize() { parent::initialize(); //Config JWT with ADmad Plugin for more info see https://github.com/ADmad/cakephp-jwt-auth $this->loadComponent('Auth', [/*..*/]); //Load Claims component $this->loadComponent('RamosISW/Jwt.Claims',[ 'claims_key' => 'data', //name where is claims on JWT Payload //Wath claims be read 'data' => [ 'user_id', 'user_email', 'user_name' ] ]); }

Working

To read claims on route that user can access, (*4)

    public function index(){
        //read user email sends on token
        $this->log($this->Claims->user_email);

        //set claims to use on view
        $this->set('Claims', $this->Claims);
    }

Token Generation

You can use \Firebase\JWT\JWT::encode() of the firebase/php-jwt lib, which this plugin depends on, to generate tokens., (*5)

The payload should have the "sub" (subject) claim whos value is used to query the Users model and find record matching the "id" field., (*6)

Generate Claims, (*7)

    public function generateToken($user){
        $token = \Firebase\JWT\JWT::encode([
                'sub' => $user['id'],
                'exp' => time() + 604800,
                'data' => [
                    'user_id' => $user['id'],
                    'user_email' => $user['email'],
                    'user_name' => $user['username']
                ]
        ], \Cake\Utility\Security::getSalt());

        return $token;
    }

The Versions

04/05 2018

dev-master

9999999-dev http://github.com/ramosisw/cakephp-jwt-claims

CakePHP plugin for read claims on jwt token

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication cakephp jwt authenticate claims

04/05 2018

1.0.0

1.0.0.0 http://github.com/ramosisw/cakephp-jwt-claims

CakePHP plugin for read claims on jwt token

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication cakephp jwt authenticate claims