JWTAuth.verifyFromHeader()

Verify a token that is provided in a request header.

Use a provided secret to decode a JSON web token coming from a request header. You may choose what algorithm you want to use to decode the JWT, but make sure to use the same algorithm that you used to encode the JWT.

Usage

Hover over inputs/exits for more info.

var JWTAuth = require('machinepack-jwtauth');


// Verify a token that is provided in a request header.

JWTAuth.verifyFromHeader({

header: 'Authorization',

secret: 'abc123jdhs3h4js',

schema: '*',

headerPrefix: 'Bearer ',

algorithm: 'HS256',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// No header with that name present within the request.

nullHeader: function () {

 

},

// OK.

success: function () {

 

},

});

Inputs

header required

The name/key of the header from which to get the token string.

'Authorization'
secret required

Secret used to decode the JSON web token.

'abc123jdhs3h4js'
schema

Example of expected token object to make available in output. Can be example object or a list/array of parameter names.

headerPrefix

Prefix attached to token within header value. This is only nessesary if you have set a prefix within the request.

'Bearer '
algorithm

The type of algorithm that is used to decode the JWT. Options: HS256, HS384, HS512 and RS256. Make sure to use the same algorithm that you used to encode the JWT.

'HS256'

Exits

error

An unexpected error occurred.

nullHeader

No header with that name present within the request.

success

OK.

(varies based on provided inputs)