GT2/GT2-Android/node_modules/jsonwebtoken/.history/tokenGenerator_201707141229...

28 lines
1.1 KiB
JavaScript
Raw Normal View History

const jwt = require('./')
function TokenGenerator (secretOrPrivateKey, secretOrPublicKey, options) {
this.secretOrPrivateKey = secretOrPrivateKey;
this.secretOrPublicKey = secretOrPublicKey;
this.options = options; //algorithm + keyid + noTimestamp + expiresIn + notBefore
}
TokenGenerator.prototype.sign = function(payload, signOptions) {
const jwtSignOptions = Object.assign({}, signOptions, this.options);
return jwt.sign(payload, this.secretOrPrivateKey, jwtSignOptions);
}
// refreshOptions.verify = options you would use with verify function
// refreshOptions.jwtid = contains the id for the new token
TokenGenerator.prototype.refresh = function(token, refreshOptions) {
const payload = jwt.verify(token, this.secretOrPrivateKey, refreshOptions.verify);
delete payload.iat;
delete payload.exp;
delete payload.nbf;
delete payload.jti; //We are generating a new token, if you are using jwtid during signing,
const jwtSignOptions = Object.assign({ jwtid: refreshOptions.jwtid }, this.options);
return jwt.sign(payload, this.secretOrPrivateKey, this.options);
}
module.exports = TokenGenerator;