verifyRequestToken()function

verifyRequestToken(request: Request, secret: PossibleBytes, caller: AnyCaller = verifyRequestToken): Promise<Data>
ParamType
requestRequest
The Request object containing an Authorization: Bearer {token} header to extract the token from. required
secretPossibleBytes
The secret key to verify the JWT signature with. required
callerAnyCaller
Identity of the calling function for error attribution. Defaults to verifyRequestToken
Return
Promise<Data>
A promise resolving to the decoded payload data from the JWT.
Throws
unknown
UnauthorizedError If the Authorization header is not set, the JWT it contains is not well-formed, or the JWT signature is invalid.

Extract the Authorization: Bearer {token} from a Request object and verify it using a signature, or throw UnauthorizedError if not set, malformed, or invalid.

Examples

const { sub, iss, customClaim } = await verifyRequestToken(request, secret)