jwt-simple
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -0,3 +1,7 @@ | ||
## 0.3.0 | ||
* Add an algorithm parameter to the decode method #16 @gregorypratt | ||
## 0.2.0 | ||
* Add the RS256 alg #7 [thedufer] |
@@ -53,7 +53,8 @@ /* | ||
* @param {String} key | ||
* @param {Boolean} noVerify | ||
* @param {Boolean} noVerify | ||
* @param {String} algorithm | ||
* @return {Object} payload | ||
* @api public | ||
*/ | ||
jwt.decode = function jwt_decode(token, key, noVerify) { | ||
jwt.decode = function jwt_decode(token, key, noVerify, algorithm) { | ||
// check seguments | ||
@@ -75,4 +76,4 @@ var segments = token.split('.'); | ||
if (!noVerify) { | ||
var signingMethod = algorithmMap[header.alg]; | ||
var signingType = typeMap[header.alg]; | ||
var signingMethod = algorithmMap[algorithm || header.alg]; | ||
var signingType = typeMap[algorithm || header.alg]; | ||
if (!signingMethod || !signingType) { | ||
@@ -129,3 +130,3 @@ throw new Error('Algorithm not supported'); | ||
return segments.join('.'); | ||
} | ||
}; | ||
@@ -171,3 +172,3 @@ | ||
function base64urlUnescape(str) { | ||
str += Array(5 - str.length % 4).join('='); | ||
str += new Array(5 - str.length % 4).join('='); | ||
return str.replace(/\-/g, '+').replace(/_/g, '/'); | ||
@@ -174,0 +175,0 @@ } |
{ | ||
"name": "jwt-simple", | ||
"description": "JWT(JSON Web Token) encode and decode module", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"author": "Kazuhito Hokamura <k.hokamura@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -5,4 +5,2 @@ # node-jwt-simple | ||
JWT is used by [Google In-App Payments](http://code.google.com/intl/en/apis/inapppayments/docs/index.html). | ||
## Install | ||
@@ -14,12 +12,14 @@ | ||
var jwt = require('jwt-simple'); | ||
var payload = { foo: 'bar' }; | ||
var secret = 'xxx'; | ||
```javascript | ||
var jwt = require('jwt-simple'); | ||
var payload = { foo: 'bar' }; | ||
var secret = 'xxx'; | ||
// encode | ||
var token = jwt.encode(payload, secret); | ||
// encode | ||
var token = jwt.encode(payload, secret); | ||
// decode | ||
var decoded = jwt.decode(token, secret); | ||
console.log(decoded); //=> { foo: 'bar' } | ||
// decode | ||
var decoded = jwt.decode(token, secret); | ||
console.log(decoded); //=> { foo: 'bar' } | ||
``` | ||
@@ -32,3 +32,5 @@ ### Algorithms | ||
// encode using HS512 | ||
jwt.encode(playload, secret, 'HS512') | ||
```javascript | ||
// encode using HS512 | ||
jwt.encode(payload, secret, 'HS512') | ||
``` |
@@ -47,2 +47,12 @@ var jwt = require('../index'); | ||
it('decode token given algorithm', function() { | ||
var obj = { foo: 'bar' }; | ||
var key = 'key'; | ||
var token = jwt.encode(obj, key, 'HS512'); | ||
var obj2 = jwt.decode(token, key, false, 'HS512'); | ||
expect(obj2).to.eql(obj); | ||
expect(jwt.decode.bind(null, token, key, false, 'HS256')).to.throwException(); | ||
expect(jwt.decode.bind(null, token, 'invalid_key')).to.throwException(); | ||
}); | ||
it('RS256', function() { | ||
@@ -49,0 +59,0 @@ var obj = { foo: 'bar' }; |
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
10401
209
34