A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec
Use composer to manage your dependencies and download PHP-JWT:
php composer require brandonlamb/php-jwt<?php
$token = new Jwt\Token();
$token
->setKey('app_key')
->setClaim('iss', 'http://example.com')
->setClaim('aud', 'http://example.com')
->setClaim('iat', 1356999524)
->setClaim('nbf', 1357000000);
$jwt = Jwt\Writer::encode($token);
$jwt = Jwt\Writer::encode($token, 'app_key', 'HS256');
$token = Jwt\Reader::decode($jwt, 'app_key');
print_r($token);
?>Run the tests using phpunit:
$ pear install PHPUnit
$ phpunit --configuration phpunit.xml.dist
PHPUnit 3.7.10 by Sebastian Bergmann.
.....
Time: 0 seconds, Memory: 2.50Mb
OK (5 tests, 5 assertions)