PHP code example of bradchesney79 / effortless-hs256-jwt
1. Go to this page and download the library: Download bradchesney79/effortless-hs256-jwt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bradchesney79 / effortless-hs256-jwt example snippets
$jwt = new Ehjwt($secretString);
use BradChesney79/EHJWT;
$jwtToken = new EHJWT('SuperSecretStringUsedForOneWayEncryption');
// the globally unique ID of this token and its series of potential reissues
$jwtToken->addOrUpdateJwtClaim('jti', '1234567890'); // it is a string. nothing more, nothing less.
// issued at
$jwtToken->addOrUpdateJwtClaim('iat', '305078400'); // my birthday...
// when this incarnation of the jwt will die as a UTC timestamp
$jwtToken->addOrUpdateJwtClaim('exp', '1887525317'); // when the T-800 comes to kill Sarah Connor
// the subject-- I use this for the publicly facing user ID
$jwtToken->addOrUpdateJwtClaim('sub', '[email protected]');
// ...I'll be honest. I don't use the not before field.
// It isn't useful to me in my software designs.
// But, it will throw an exception if you try to use it before allowed.
// $jwtToken->addOrUpdateJwtClaim('nbf', 0); // January 1st, 1970
// One of many allowable custom, private claims-- but, beware, smaller the better.
$jwtToken->addOrUpdateJwtClaim('key','value');
$jwtToken->createToken(); // this internally populates the JWT string property of your instance
echo $jwtToken->getToken(); // this gives you the three part, period delimited string stored in the JWT string property
$jwtToken = new EHJWT('SuperSecretStringUsedForOneWayEncryption');
if ($jwtToken->loadToken('fdsafdsafdsafdsa'.'fdsfdsafdsafdsa'.'fdsafdfadsfdsafdsa')) {
$sessionDataArray = $jwtToken->getTokenClaims();
}
$this->clearClaims();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.