createToken() public method

The default algorithm used is HS256. To set a custom one, set the env variable JWT_ALGO.
public createToken ( GenTux\Jwt\JwtPayloadInterface | array $payload, string | null $secret = null, string | null $algo = null ) : JwtToken
$payload GenTux\Jwt\JwtPayloadInterface | array
$secret string | null
$algo string | null
return JwtToken
コード例 #1
0
 public function it_encodes_to_json_as_a_string_representation_of_the_token(JwtDriverInterface $jwt)
 {
     $driver = new FirebaseDriver();
     $jwt = new JwtToken($driver);
     $token = $jwt->createToken(['exp' => time() + 100], 'secret');
     $serialized = json_encode(['token' => $token]);
     $decoded = json_decode($serialized);
     if (!is_string($decoded->token) || strlen($decoded->token) < 1) {
         throw new FailureException('Token was not json encoded.');
     }
 }