JWT.decode()

Decode a JWT.

Decode a JSON web token with a provided secret. 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 JWT = require('machinepack-jwt');


// Decode a JWT.

JWT.decode({

secret: 'abc123jdhs3h4js',

token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ',

schema: '*',

algorithm: 'HS256',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function () {

 

},

});

Inputs

secret required

Secret used to decode the JSON web token.

'abc123jdhs3h4js'
token required

JSON web token to decode.

'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ'
schema

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

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.

success

OK.

(varies based on provided inputs)