lib/index.js
function getTokenFromHeader(request) {
  if (!request.headers || !request.headers.has('authorization')) {
    throw new UnauthorizedError('No authorization header present');
  }

  const parts = request.headers.get('authorization').split(" ");

  if (parts.length === 2) {
    const scheme = parts[0];
    const credentials = parts[1];

    if (/^Bearer$/i.test(scheme)) {
      return credentials;
    } else {
      throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
    }
  } else {
    throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
  }
}
function getTokenFromHeader(request) {
  if (!request.headers || !request.headers.has('authorization')) {
    throw new UnauthorizedError('No authorization header present');
  }

  const parts = request.headers.get('authorization').split(" ");

  if (parts.length === 2) {
    const scheme = parts[0];
    const credentials = parts[1];

    if (/^Bearer$/i.test(scheme)) {
      return credentials;
    } else {
      throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
    }
  } else {
    throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
  }
}
function getTokenFromHeader ( request ) { if ( ! request . headers || ! request . headers . has ( 'authorization' ) ) { throw new UnauthorizedError ( 'No authorization header present' ) ; } const parts = request . headers . get ( 'authorization' ) . split ( " " ) ; if ( parts . length === 2 ) { const scheme = parts [ 0 ] ; const credentials = parts [ 1 ] ; if ( / ^Bearer$ / i . test ( scheme ) ) { return credentials ; } else { throw new UnauthorizedError ( 'Bad Authorization header format. Format is "Authorization: Bearer token"' ) ; } } else { throw new UnauthorizedError ( 'Bad Authorization header format. Format is "Authorization: Bearer token"' ) ; } }
Retrieves the JWT from the authorization header
@param request
@returns {string} The JWT
Retrieves the JWT from the authorization header