Decoding and verifying JWT, (*10)
$encodedJwt = 'abcdef.ghijklm.nopqrstuvw';
$jws = Jws::parse($encodedJwt);
$jws->getPayload()->issuedAt; //Access to the registered JWT claims
$jws->getPayload()->getCustomClaim('user_id'); //Access to the custom claims.
$jws->getHeader()->getAlgorithm(); //Access to the JOSE header parameters.
Verifying signature, (*11)
$encodedJwt = 'abcdef.ghijklm.nopqrstuvw';
$jws = Jws::parse($encodedJwt);
//For symmetric algorithm:
$jws->privateKey = 'YoUr_SeCrEt';
//For asymmetric algorithm:
$jws->certificate = 'file:///path/to/certificate.pem'; //Path to the PEM encoded X.509 certificate.
$jws->verify(); //TRUE if the signature is valid.
If the signature is valid, you have to validate the JWT claims., (*12)
$jws->getPayload()->verify(); //Returns TRUE if the JWT is valid, otherwise it returns a string that contains an error message.
To validate "jti" value you need to create two anonymous functions, and pass them as arguments to the verify method., (*13)
$setJti = function($jti)
{
//Writes "jti" value into storage. (E.g. Redis Db)
};
//This function must return TRUE if the given value exists in storage, false otherwise.
$getJti = function($jti)
{
//...
};
$jws->getPayload()->verify($setJti, $getJti);