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.
Implements
Section titled “Implements”ValFieldTesterIndexer
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Token(
options?):Token
Parameters
Section titled “Parameters”options?
Section titled “options?”TokenOptions = {}
Returns
Section titled “Returns”Token
Properties
Section titled “Properties”algorithm
Section titled “algorithm”
readonlyalgorithm:string
algorithm is the alg header value.
audience
Section titled “audience”
readonlyaudience: readonlystring[]
audience is the aud claim, always held as a list.
authorizedParty
Section titled “authorizedParty”
readonlyauthorizedParty:string
authorizedParty is the azp claim, or the empty string when absent.
expiresAt
Section titled “expiresAt”
readonlyexpiresAt:Timestamp
expiresAt is the exp claim.
readonlyid:string
id is the jti claim, or the empty string when absent.
issuedAt
Section titled “issuedAt”
readonlyissuedAt:Timestamp
issuedAt is the iat claim.
issuer
Section titled “issuer”
readonlyissuer:string
issuer is the iss claim.
readonlykeyId:string
keyId is the kid header value, or the empty string when absent.
notBefore
Section titled “notBefore”
readonlynotBefore:Timestamp
notBefore is the nbf claim, or the zero timestamp when absent.
payload
Section titled “payload”
readonlypayload:Record<string,unknown>
payload contains the decoded claim set, including custom claims.
subject
Section titled “subject”
readonlysubject:string
subject is the sub claim.
Methods
Section titled “Methods”claim()
Section titled “claim()”claim(
adapter,claimName):Val
claim reads a claim from the token payload, returning an empty optional when it is absent or JSON null.
Parameters
Section titled “Parameters”adapter
Section titled “adapter”TypeAdapter
claimName
Section titled “claimName”string
Returns
Section titled “Returns”Val
convertToNative()
Section titled “convertToNative()”convertToNative(
typeDesc):unknown
convertToNative returns the token itself, the only native representation it has.
Parameters
Section titled “Parameters”typeDesc
Section titled “typeDesc”unknown
Returns
Section titled “Returns”unknown
Implementation of
Section titled “Implementation of”Val.convertToNative
convertToType()
Section titled “convertToType()”convertToType(
typeValue):Val
convertToType converts a token to its own type or to type metadata.
Parameters
Section titled “Parameters”typeValue
Section titled “typeValue”Type
Returns
Section titled “Returns”Val
Implementation of
Section titled “Implementation of”Val.convertToType
equal()
Section titled “equal()”equal(
other):Val
equal reports whether another token carries the same claims.
Parameters
Section titled “Parameters”Val
Returns
Section titled “Returns”Val
Implementation of
Section titled “Implementation of”Val.equal
get(
index):Val
get returns a declared claim by its CEL field name.
Parameters
Section titled “Parameters”Val
Returns
Section titled “Returns”Val
Implementation of
Section titled “Implementation of”Indexer.get
isSet()
Section titled “isSet()”isSet(
field):Val
isSet reports whether a declared claim carries a value rather than its default.
Parameters
Section titled “Parameters”Val
Returns
Section titled “Returns”Val
Implementation of
Section titled “Implementation of”FieldTester.isSet
isValidAt()
Section titled “isValidAt()”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.
Parameters
Section titled “Parameters”refTime
Section titled “refTime”Timestamp
leeway?
Section titled “leeway?”Duration = ...
Returns
Section titled “Returns”boolean
presentedBy()
Section titled “presentedBy()”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.
Parameters
Section titled “Parameters”issuer
Section titled “issuer”string
presenter
Section titled “presenter”string
Returns
Section titled “Returns”boolean
type()
Section titled “type()”type():
Type
type returns the CEL token type.
Returns
Section titled “Returns”Type
Implementation of
Section titled “Implementation of”Val.type
value()
Section titled “value()”value():
unknown
value returns the token itself.
Returns
Section titled “Returns”unknown
Implementation of
Section titled “Implementation of”Val.value