Package Exports
- jwthelper
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jwthelper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
jwthelper
An easy to use helper class for jsonwebtoken.
Install
npm install jwthelper --saveUsage
var helper = JWTHelper.createJWTHelper([options]);options:algorithm: an algorithm for signing supported by jsonwebtoken (default HS512)secret: a string containing the secret to encode the token withprivateKey: a private key to encode the token withexpiresInMinutesorexpiresInSeconds: set jwt expirationnoTimestamp: omit the timestamp in the jwt payload'ignoreExperiation': ignore expiration settings when verifying a jwt
audience: set the audience for signing and verifyingissuer: set the issuer for signing and verifyingsubject: set the subject for signing and verifyingheaders: an optional array containig header fieldsvar jwt = helper.sign(payload[, signOptions]);
Signs a JWT with the payload, The optional signOptions accept all options mentioned above and will be used for this signing only.
helper.verify(token, [verifyOptions, ]callback);Verifies a token. The callback conforms to the standard (error, payload) scheme. verifyOptions accepts all optios mentioned above and will be used for this verification only.
helper.setOptions(options);Updates the options for the helper. The options array accepts all parameters mentioned above.
Example
var JWTHelper = require('jwthelper');
// Create a new helper and set the options for that helper
var helper = JWTHelper.createJWTHelper({
'secret': 'this is my secret'
});
// Signing a JWT
var jwt = helper.sign({
'_id': 55,
'isAdmin': true
});
// This outputs the signed JWT
console.log(jwt);
// Now we are going to decode it!
helper.verify(jwt, function(err, decoded) {
if(err) return console.log((err.name == 'JsonWebTokenError') ? 'Invalid token' : err.name);
// And we display the decoded JWT
console.log(decoded);
});Version history
- 0.0.1 - 12 July 2015
- First release
License
Copyright 2015 Michiel van der Velde.
This software is licensed under the MIT License