1. Go to this page and download the library: Download artisangang/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/ */
$token = new Token;
$token->setKey('secret);
$token->setIssuer('who issued this token');
$token->setSubject('subject of token');
$token->setAudience('recipients');
// of in case of multiple audience
//$token->setAudience('recipient1', 'recipient2', 'recipient3');
// this will work with unix timestamp
$token->setExpiry(time() + 60);
// this token cannot be used before
$token->setNotBefore(time() + 10);
// token issued at unix time stamp
// Note: token cannot be used before issued at time
$token->setIssuedAt(time());
$token->setIdentity('this must be unique');
$token->setType('jwt');
// suported algorithm: HS256,HS512,HS384
// for oppen ssl : RS256,RS384,RS512
$token->setAlgorithm('HS256');
// add custom claims to token
$token->setClaim('user_id', 1);
$token->setClaim('email', '[email protected]');
// generate token based on claims
$tokenString = $token->get();
// use one from below methods
try {
// this will return array of claims
$token = Token::validate('token string', 'your key');
// you may validate custom claims here
} catch(\Exception $e)
{
//InvalidArgumentException -> some dException -> token is expired
}
// or by using check, this will return bool
if (!Token::check('token string', 'your key'))
{
// token is not valid
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.