Token.encode

encodes the token

  1. string encode(string secret)
    class Token
    string
    encode
    (
    string secret
    )
  2. string encode()

Parameters

secret string

the secret key used to sign the token

Return Value

Type: string

base64 representation of the token including signature

Examples

Token token = new Token(JWTAlgorithm.HS512);

long now = Clock.currTime.toUnixTime();

string secret = "super_secret";

token.claims.exp = now - 3600;

assertThrown!ExpiredException(token.encode(secret));

token.claims.exp = now + 3600;

token.claims.nbf = now + 7200;

assertThrown!ExpiresBeforeValidException(token.encode(secret));

Meta