jose.jwt

index · jose

Overview

JSON Web Tokens (RFC 7519): a claims table signed as the payload of a jose.jws. encode adds typ: JWT; verify checks the signature through jose.jws, then typ, the claims the caller requires, the three time claims against a clock with leeway, and iss and aud against what the caller expects. An aud the caller did not ask for fails the token, as RFC 7519 §4.1.3 has it.

Functions

NameSignature
encodeencode(claims, key, header) -> token, err
decodedecode(token) -> header, claims
verifyverify(token, keys, opts) -> claims, header

encode(claims, key, header) -> token, err

Sign a claims table as a JWT

The header is jose.jws.sign's, with typ set to JWT unless header carries its own. Raises on claims that are not a table.

decode(token) -> header, claims

Decode a token's header and claims without verifying it

Nothing it returns is trusted; it reads a kid or an iss before a key is chosen.

verify(token, keys, opts) -> claims, header

Verify a token and return its claims

keys and opts.algs are jose.jws.verify's. The other options:

optiondefaultcheck
typJWTheader typ, when present, equals it, any case
require{ "exp" }every named claim is present; {} requires none
nowos.time()the clock the time claims are read against
leeway0seconds of slack on every time claim
issnoneiss equals it
audnoneaud is it, or an array holding it

exp, nbf and iat must be finite numbers when present: the token is good while now - leeway < exp, nbf <= now + leeway and iat <= now + leeway. A token carrying aud fails when no aud is expected. On success the second value is the header.