node-token-extractor
Extracts access_token
from a HTTP request header Authorization: Bearer <access_token>
Install
$ npm install token-extractor --save
Usage
tokenExtractor(req, callback)
Arguments
req
: HTTP Node.js requestcallback(err, token)
: A callback which is called with either the token extracted from the header or a possible error.
Example
const tokenExtractor = ; ;
Error handling
TokenExtractorError
Possible thrown errors
message | code |
---|---|
No Authorization header is present | E_AUTHORIZATION_REQUIRED |
Format is :: Authorization: Bearer | E_AUTHORIZATION_INVALID_FORMAT |
Authorization token was not found | E_AUTHORIZATION_TOKEN_NOT_FOUND |
Example
Suppose E_AUTHORIZATION_TOKEN_NOT_FOUND
error was thrown
);
Test
$ npm test