JWT(JSON Web Token) encode and decode module for PHP.
$ composer require naux/jwt
$secret = 'xxx';
$jwt = new \Naux\JWT($secret);
$payload = ['iss' => 1, 'exp' => 1450539234, 'foo' => 'bar'];
// encode
$token = $jwt->encode($payload);
// decode
$decoded = $jwt->decode($token);
var_dump($decoded);
By default the algorithm to encode is HS256
.
The supported algorithms for encoding and decoding are ECDSA
, ES256
, ES384
, ES512
, HMAC
, HS256
, HS384
, HS512
, PublicKey
, RS256
, RS384
, RS512
, RSA
.
// using HS512
$jwt = new JWT('secret', 'HS512');