public static create ( Emarref\Jwt\Algorithm\AlgorithmInterface $algorithm ) : |
||
$algorithm | Emarref\Jwt\Algorithm\AlgorithmInterface | |
return |
public static function create(Algorithm\AlgorithmInterface $algorithm)
{
if ($algorithm instanceof Algorithm\AsymmetricInterface) {
$encryption = new Asymmetric($algorithm);
} elseif ($algorithm instanceof Algorithm\SymmetricInterface) {
$encryption = new Symmetric($algorithm);
} else {
throw new \InvalidArgumentException(sprintf('Algorithm of class "%s" is neither symmetric or asymmetric.', get_class($algorithm)));
}
return $encryption;
}
protected static function authorization() { $token = new Emarref\Jwt\Token(); $parameter = new Emarref\Jwt\HeaderParameter\Custom('typ', 'JWT'); $token->addHeader($parameter, true); $token->addClaim(new Emarref\Jwt\Claim\Expiration(new \DateTime(self::$duration))); $jwt = new Emarref\Jwt\Jwt(); $algorithm = new Emarref\Jwt\Algorithm\Hs256(self::$appSecret); $encryption = Emarref\Jwt\Encryption\Factory::create($algorithm); $serializedToken = $jwt->serialize($token, $encryption); return $serializedToken; }