Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

Functions

  • Function that validate and get the token from the header request and will return a 401 if a valid JWT bearer token in the request is not provided or has an invalid format.

    Since is agnostic to the framework, it needs to be called within a middleware and is not necessary to pass the complete headers object since each framework has different ways to handle the request object, it could be an small object with authorization and content-type headers only.

    Example:

    function AuthMiddleware(req, res, next) {
    const token = getToken(req.headers);

    // Verify token with JwtVerifier
    }
    function AuthMiddleware(req, res, next) {
    const { authorization, content-type } = myFrameworksHeadersObjectOrFunction();
    const token = getToken({ authorization, content-type });

    // Verify token with JwtVerifier
    }

    Parameters

    • headers: HeadersLike

      Headers to search for the token. Must contain an authorization and content-type header.

    Returns string

    Token as string