Skip to content

mikaelletang/jwt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

A JWT implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published