jsonwebtoken
Advanced tools
Comparing version 4.0.0 to 4.1.0
16
index.js
@@ -8,3 +8,15 @@ var jws = require('jws'); | ||
var decoded = jws.decode(jwt, options); | ||
return decoded && decoded.payload; | ||
var payload = decoded && decoded.payload; | ||
//try parse the payload | ||
if(typeof payload === 'string') { | ||
try { | ||
var obj = JSON.parse(payload); | ||
if(typeof obj === 'object') { | ||
return obj; | ||
} | ||
} catch (e) { } | ||
} | ||
return payload; | ||
}; | ||
@@ -113,3 +125,3 @@ | ||
try { | ||
payload = this.decode(jwtString); | ||
payload = this.decode(jwtString); | ||
} catch(err) { | ||
@@ -116,0 +128,0 @@ return done(err); |
{ | ||
"name": "jsonwebtoken", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "JSON Web Token implementation (symmetric and asymmetric)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var jwt = require('../index'); | ||
var expect = require('chai').expect; | ||
var JsonWebTokenError = require('../lib/JsonWebTokenError'); | ||
@@ -12,2 +13,9 @@ describe('non_object_values values', function() { | ||
it('should fail to validate audience when the payload is string', function () { | ||
var token = jwt.sign('hello', '123'); | ||
expect(function () { | ||
jwt.verify(token, '123', { audience: 'foo' }); | ||
}).to.throw(JsonWebTokenError); | ||
}); | ||
it('should work with number', function () { | ||
@@ -14,0 +22,0 @@ var token = jwt.sign(123, '123'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33882
20
564
2