A JWT implementation
PHP
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 45 commits behind emarref:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
LICENSE
README.md
composer.json
phpunit.xml

README.md

Work in Progress

Intended to eventually be a full implementation of the JWT standard.

More info

Functional example

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)