Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

ClaimCheck<R>: (predicate: (payload: JWTPayload) => boolean, errorMsg?: string) => R

Type parameters

Type declaration

    • (predicate: (payload: JWTPayload) => boolean, errorMsg?: string): R
    • Parameters

      Returns R

ClaimEquals<R>: (claim: string, expected: JSONPrimitive) => R

Type parameters

Type declaration

ClaimIncludes<R>: (claim: string, ...expected: JSONPrimitive[]) => R

Type parameters

Type declaration

RequiredPermissions<R>: (permissions: string | string[]) => R

Type parameters

Type declaration

    • (permissions: string | string[]): R
    • Parameters

      • permissions: string | string[]

      Returns R

RequiredScopes<R>: (scopes: string | string[]) => R

Type parameters

Type declaration

    • (scopes: string | string[]): R
    • Parameters

      • scopes: string | string[]

      Returns R

Functions

  • claimCheck(predicate: (payload: JwtPayload) => boolean, errorMsg?: string): ClaimChecker
  • Function that applies any validation predicate or function to the jwt payload. It will return validation exceptions if something fail.

    Since is agnostic to the framework, it needs to be called within a middleware.

    Example:

    function myFunction(req, res, next) {
    const validateIis = (payload) => payload.iss === 'my-domain.com';
    const check = claimCheck(validateIis, 'my validation error message');

    if (check(req.auth.payload)) {

    // Do something
    }

    Parameters

    • predicate: (payload: JwtPayload) => boolean

      Validation predicate or function that receives the jwt payload as parameter.

        • (payload: JwtPayload): boolean
        • Parameters

          • payload: JwtPayload

          Returns boolean

    • Optional errorMsg: string

      Error message to return if the validation fails.

    Returns ClaimChecker

    Validation exceptions if the claim is not included or expected values are not in the claim value.

  • Function that validates if a claim's value is equal to an specific value in the jwt payload. It will return validation exceptions if something fail.

    Since is agnostic to the framework, it needs to be called within a middleware.

    Example:

    function myFunction(req, res, next) {
    const isEqual = claimEquals(scope, 'email');

    if (isEqual(req.auth.payload)) {

    // Do something
    }

    Parameters

    • claim: string

      Claim name. eg: scope.

    • expected: JSONPrimitive

      Expected claim value. eg: claimEquals('scope', 'email profile')

    Returns ClaimChecker

    Validation exceptions if the claim is not included or expected values are not in the claim value.

  • Function that validate if a claim is included or not in the jwt payload and if the claim includes the values passed as parameters. It will return validation exceptions if something fail.

    Since is agnostic to the framework, it needs to be called within a middleware.

    Example:

    function myFunction(req, res, next) {
    const validate = claimIncludes('scope', 'email', 'profile');

    if (validate(req.auth.payload)) {

    // Do something
    }

    Parameters

    • claim: string

      Claim name. eg: scope.

    • Rest ...expected: JSONPrimitive[]

      Claim values as parameters. eg: claimIncludes('scope', 'email', 'profile')

    Returns ClaimChecker

    Validation exceptions if the claim is not included or expected values are not in the claim value.

  • requiredPermissions(permissions: string | string[]): ClaimChecker
  • Function that validates if permissions claim contains the required permissions in the jwt payload. It will return validation exceptions if something fail.

    Since is agnostic to the framework, it needs to be called within a middleware.

    Example:

    function myFunction(req, res, next) {
    const isAdmin = requiredPermissions('admin');

    if (isAdmin(req.auth.payload)) {

    // Do something
    }

    Parameters

    • permissions: string | string[]

      Single or multiple permissions to check.

    Returns ClaimChecker

    Validation exceptions if the claim is not included or expected values are not in the claim value.

  • Function that validates if scope claim contains the required scopes in the jwt payload. It will return validation exceptions if something fail.

    Since is agnostic to the framework, it needs to be called within a middleware.

    Example:

    function myFunction(req, res, next) {
    const canReadUserInfo = requiredScopes(['email', 'profile']);

    if (canReadUserInfo(req.auth.payload)) {

    // Do something
    }

    Parameters

    • scopes: string | string[]

      Single or multiple scopes to check.

    Returns ClaimChecker

    Validation exceptions if the claim is not included or expected values are not in the claim value.