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.
| Name | Signature |
|---|---|
| encode | encode(claims, key, header) -> token, err |
| decode | decode(token) -> header, claims |
| verify | verify(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:
| option | default | check |
|---|---|---|
typ | JWT | header typ, when present, equals it, any case |
require | { "exp" } | every named claim is present; {} requires none |
now | os.time() | the clock the time claims are read against |
leeway | 0 | seconds of slack on every time claim |
iss | none | iss equals it |
aud | none | aud 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.