Skip to content

Token

Token is a parsed JWT, and is itself the CEL value of a token.

A token and its payload must be treated as read-only once created.

Being a CEL value rather than a described plain object keeps a token’s fields readable through any adapter: cel-go reads the configured type adapter off the environment when a token is returned, and the port has no equivalent hook.

Signature verification is out of scope. Verify a token before handing it to CEL.

  • Val
  • FieldTester
  • Indexer

new Token(options?): Token

TokenOptions = {}

Token

readonly algorithm: string

algorithm is the alg header value.


readonly audience: readonly string[]

audience is the aud claim, always held as a list.


readonly authorizedParty: string

authorizedParty is the azp claim, or the empty string when absent.


readonly expiresAt: Timestamp

expiresAt is the exp claim.


readonly id: string

id is the jti claim, or the empty string when absent.


readonly issuedAt: Timestamp

issuedAt is the iat claim.


readonly issuer: string

issuer is the iss claim.


readonly keyId: string

keyId is the kid header value, or the empty string when absent.


readonly notBefore: Timestamp

notBefore is the nbf claim, or the zero timestamp when absent.


readonly payload: Record<string, unknown>

payload contains the decoded claim set, including custom claims.


readonly subject: string

subject is the sub claim.

claim(adapter, claimName): Val

claim reads a claim from the token payload, returning an empty optional when it is absent or JSON null.

TypeAdapter

string

Val


convertToNative(typeDesc): unknown

convertToNative returns the token itself, the only native representation it has.

unknown

unknown

Val.convertToNative


convertToType(typeValue): Val

convertToType converts a token to its own type or to type metadata.

Type

Val

Val.convertToType


equal(other): Val

equal reports whether another token carries the same claims.

Val

Val

Val.equal


get(index): Val

get returns a declared claim by its CEL field name.

Val

Val

Indexer.get


isSet(field): Val

isSet reports whether a declared claim carries a value rather than its default.

Val

Val

FieldTester.isSet


isValidAt(refTime, leeway?): boolean

isValidAt reports whether the token’s time claims hold at the reference time, allowing the given clock leeway in both directions.

An unset claim is skipped, so a token carrying none of iat, nbf, and exp is always valid.

Timestamp

Duration = ...

boolean


presentedBy(issuer, presenter): boolean

presentedBy reports whether a token from issuer was presented by presenter.

A token carrying an azp claim is checked against that claim alone; otherwise the presenter must appear in the aud claim.

string

string

boolean


type(): Type

type returns the CEL token type.

Type

Val.type


value(): unknown

value returns the token itself.

unknown

Val.value