-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audience, issuer, expiration, etc are lost when using a string as payload. #6
Comments
can you show a code example or ideally a test? |
This tests will cause the node-jws library to raise a SintaxError. I did a pull request to that library today. A workaround is to serialize the payload with JSON.stringify before sending it to node-jws. This can be done for example in the sing function of node-jsonwebtoken. Then, the second test will fail because the properties attached to the string payload are lost and thus the payload doesn't has any expiration date. describe('when signing a token with a string as payload', function() {
var secret = 'shhhhhh';
var payload = 'relevant string goes here';
it('should validate with secret', function(done) {
var token = jwt.sign(payload, secret);
jwt.verify(token, secret, function(err, decoded) {
assert.ok(decoded);
assert.equal(payload, decoded);
done();
});
});
it('should be invalid when is expired', function(done) {
var token = jwt.sign(payload, secret, { expiresInMinutes: -10 });
jwt.verify(token, secret, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
done();
});
});
}); By the way, very interesting the blog of your company : ) |
I think this is in the same issue category,
outputs the following: [Function: String] |
SOrry invalidate my previous comment, header was commint without the "typ" field, which is causing the jws module to not json decode once again:
my current solution will be to use the "opt" to force the serialization. |
I have come across the same issue when using an integer as the payload. Not a big deal to workaround (now pass my integer as a value in JSON object), but it was mystifying at first why no tokens were expiring.
results in '10909334' being printed to the console. |
yes, payload needs to be an object today |
When using a string as payload, the issuer, expiration, audience and subject are lost. It is not possible to attach properties to a primitive and also they do not get serialized anyway, as it get serialized as a string. A possible solution is to put the string in a object literal and attach this data to the literal too.
At the moment, using a string as payload also causes a parsing exception when decoding it due to a problem in the node-jws library.
The text was updated successfully, but these errors were encountered: