JWT.encode()

Encode a JWT.

Encode a JSON web token with a provided secret. You may choose what algorithm you want to use to encode the JWT, but make sure to use the same algorithm when you are decoding the JWT.

Usage

Hover over inputs/exits for more info.

var JWT = require('machinepack-jwt');


// Encode a JWT.

JWT.encode({

secret: 'abc123jdhs3h4js',

payload: '*',

algorithm: 'HS256',

expires: 43200,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

secret required

The secret used to encode the JWT.

'abc123jdhs3h4js'
payload required

The contents of the JWT.

algorithm

The type of algorithm that is used to encode the JWT. Options: HS256, HS384, HS512 and RS256.

'HS256'
expires

Number of minutes until the token expires.

43200

Exits

error

An unexpected error occurred.

success

OK.

'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ'