2017 © Pedro Peláez
 

library jwt

Json Web Token (JWT) PHP implementation

image

gamegos/jwt

Json Web Token (JWT) PHP implementation

  • Thursday, April 9, 2015
  • by glkz
  • Repository
  • 18 Watchers
  • 15 Stars
  • 867 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

PHP JSON Web Token (JWT) Library

JSON Web Token (JWT) implementation based on draft-ietf-oauth-json-web-token-25., (*1)

Installation

The recommended way to install gamegos/jws is through Composer., (*2)

{
    "require": {
        "gamegos/jwt": "~0.1"
    }
}

Basic Usage

Encoding, (*3)

$key = 'some-secret-for-hmac';
$alg = 'HS256';

$token = new \Gamegos\JWT\Token();
$token->setClaim('sub', 'someone@example.com'); // alternatively you can use $token->setSubject('someone@example.com') method
$token->setClaim('exp', time() + 60*5);

$encoder = new \Gamegos\JWT\Encoder();
$encoder->encode($token, $key, $alg);

printf("JWT TOKEN: %s\n", $token->getJWT()); //eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzb21lb25lQGV4YW1wbGUuY29tIiwiZXhwIjoxNDA4NDUzNzkwfQ.2Fk5-UUMhOAcQH812LL0sdaf29zuf293nLhHp_VKBDg


Validation, (*4)


$jwtString = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzb21lb25lQGV4YW1wbGUuY29tIiwiZXhwIjoxNDA4NDUyMzcxfQ.Fy1DLdfZBiR_khyTsghItDW3_1rM7osz_IxjiaiRto0'; $key = 'some-secret-for-hmac'; try { $validator = new \Gamegos\JWT\Validator(); $token = $validator->validate($jwtString, $key); print_r($token->getClaims()); print_r($token->getHeaders()); } catch (\Gamegos\JWT\Exception\JWTException $e) { printf("Invalid Token:\n %s\n", $e->getMessage()); //$e->getToken(); }

See examples folder for sample code., (*5)

Supported Signature Algorithms

This package uses gamegos/jws for signing tokens. Currently supported signature and mac algorithms:, (*6)

  • HS256, HS384, HS512 (HMAC using SHA-XXX)
  • RS256, RS384, RS512 (RSASSA-PKCS-v1_5 using SHA-XXX)

Details can be found here., (*7)

The Versions

09/04 2015

dev-master

9999999-dev

Json Web Token (JWT) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mustafa Altun

jwt jws json web token json token

09/04 2015

0.1.1

0.1.1.0

Json Web Token (JWT) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mustafa Altun

jwt jws json web token json token

19/08 2014

0.1.0

0.1.0.0

Json Web Token (JWT) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mustafa Altun

jwt jws json web token json token