Intended to eventually be a full implementation of the JWT standard.
- JSON Web Token (JWT)
- JSON Web Encryption (JWE)
- JSON Web Signature (JWS)
- JSON Web Algorithms (JWA)
- JSON Web Key (JWK)
require_once 'vendor/autoload.php';
$jwt = new \Emarref\Jwt\Jwt();
$token = new \Emarref\Jwt\Token();
$token->addClaim(new \Emarref\Jwt\Claim\Issuer('uri://foobar'));
$token->addClaim(new \Emarref\Jwt\Claim\Expiration(new \DateTime('30 minutes')));
$encodedToken = $jwt->serialize($token, new \Emarref\Jwt\Algorithm\Hs256('verysecret'));
// -> eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ1cmk6XC9cL2Zvb2JhciIsImV4cCI6MTQxNTA3MTMxNX0.mf2LLMA1fzd04L5438JcBwWyx9l7rY1_mHBiwrOxpDs
$token = $jwt->deserialize('eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ1cmk6XC9cL2Zvb2JhciIsImV4cCI6MTQxNTA3MTMxNX0.mf2LLMA1fzd04L5438JcBwWyx9l7rY1_mHBiwrOxpDs');
$context = new \Emarref\Jwt\Verification\Context();
$context->setAlgorithm(new \Emarref\Jwt\Algorithm\Hs256('verysecret'));
$context->setIssuer('uri://foobar');
var_dump($jwt->verify($token, $context));
// -> bool(true)