Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JwtHandler

Service class providing functionality to handle and verify JSON Web Tokens.

Hierarchy

  • JwtHandler

Index

Methods

decodeJwtClaims

  • decodeJwtClaims(token: string): JwtClaims | null
  • Decodes a Base64Url encoded JSON Web Token.

    Parameters

    • token: string

      the JWT token

    Returns JwtClaims | null

    the decoded JSON object or null if it is not a JWT token

decodeJwtHeader

  • decodeJwtHeader(token: string): JwtHeader | null
  • Decodes a Base64Url encoded JSON Web Token header.

    Parameters

    • token: string

      the JWT token

    Returns JwtHeader | null

    the decoded JSON header parameters or null if it is not a JWT token

validateJwt

  • validateJwt(claims: JwtClaims, validation: { aud?: undefined | string; iss?: undefined | string; jti?: undefined | string; sub?: undefined | string }, leeway?: number): Promise<void>
  • Validates the given decoded JWT token. Checks if the given claims align with the validation claims. Furthermore the token's nbf and exp claims are checked if they are defined in the token. A small leeway, usually no more than a few minutes, may be used to account for clock skew.

    Parameters

    • claims: JwtClaims

      the decoded JWT token

    • validation: { aud?: undefined | string; iss?: undefined | string; jti?: undefined | string; sub?: undefined | string }

      the reference claims to check

      • Optional aud?: undefined | string
      • Optional iss?: undefined | string
      • Optional jti?: undefined | string
      • Optional sub?: undefined | string
    • Default value leeway: number = 60000

      a small leeway to account for clock skew

    Returns Promise<void>

    an empty promise that resolves if the token is valid

verifyJwt

  • verifyJwt(token: string, key: CryptoKey): Promise<void>
  • Verifies the signature of the given JSON Web Token.

    Parameters

    • token: string

      the JWT token

    • key: CryptoKey

      the key to check the token against

    Returns Promise<void>

    an empty promise that resolves if the token is valid

Generated using TypeDoc