From fa88327d5ec98e2ce1792dd2514f58174af26b12 Mon Sep 17 00:00:00 2001 From: codedawi Date: Sun, 6 Oct 2019 20:07:21 -0400 Subject: [PATCH 1/3] Fixes missing identity value in token when it's not a string in AccessToken constuctor --- .gitignore | 3 +++ lib/jwt/AccessToken.js | 1 + spec/unit/jwt/AccessToken.spec.js | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 99a447b84f..c3defe02ad 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ config.js ### jsdoc dir ### docs + +### ide / editors ### +.vscode \ No newline at end of file diff --git a/lib/jwt/AccessToken.js b/lib/jwt/AccessToken.js index bd72de4e15..34c17aebef 100644 --- a/lib/jwt/AccessToken.js +++ b/lib/jwt/AccessToken.js @@ -212,6 +212,7 @@ function AccessToken(accountSid, keySid, secret, options) { if (!keySid) { throw new Error('keySid is required'); } if (!secret) { throw new Error('secret is required'); } options = options || {}; + if (_.isInteger(options.identity)) { options.identity = new String(options.identity); }; this.accountSid = accountSid; this.keySid = keySid; diff --git a/spec/unit/jwt/AccessToken.spec.js b/spec/unit/jwt/AccessToken.spec.js index 1006828de2..fe14f7e1ae 100644 --- a/spec/unit/jwt/AccessToken.spec.js +++ b/spec/unit/jwt/AccessToken.spec.js @@ -28,6 +28,11 @@ describe('AccessToken', function() { it('should require secret', function() { expect(initWithoutIndex(2)).toThrow(new Error('secret is required')); }); + it('should convert identity from integer to string', function () { + var token = new twilio.jwt.AccessToken(accountSid, keySid, 'secret', { identity: 4444 }); + var decoded = jwt.decode(token.toJwt()); + expect(decoded.grants.identity).toEqual('4444'); + }); }); describe('generate', function() { From 2aebc5b55fd75d179f13e059d072ad13d9f1e2b4 Mon Sep 17 00:00:00 2001 From: codedawi Date: Thu, 17 Oct 2019 20:21:23 -0400 Subject: [PATCH 2/3] Moving conversion of indentity toString into toJwt function rather than constuctor --- lib/jwt/AccessToken.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jwt/AccessToken.js b/lib/jwt/AccessToken.js index 34c17aebef..44054db27f 100644 --- a/lib/jwt/AccessToken.js +++ b/lib/jwt/AccessToken.js @@ -212,7 +212,6 @@ function AccessToken(accountSid, keySid, secret, options) { if (!keySid) { throw new Error('keySid is required'); } if (!secret) { throw new Error('secret is required'); } options = options || {}; - if (_.isInteger(options.identity)) { options.identity = new String(options.identity); }; this.accountSid = accountSid; this.keySid = keySid; @@ -250,7 +249,7 @@ _.extend(AccessToken.prototype, { } var grants = {}; - if (_.isString(this.identity)) { grants.identity = this.identity; } + if (_.isInteger(this.identity) || _.isString(this.identity)) { grants.identity = String(this.identity); }; _.each(this.grants, function(grant) { grants[grant.key] = grant.toPayload(); From 24d08d196c950bf8872028bed2d5ad4abac3d090 Mon Sep 17 00:00:00 2001 From: childish-sambino Date: Fri, 18 Oct 2019 09:33:56 -0500 Subject: [PATCH 3/3] Remove extra semicolon from AccessToken.js --- lib/jwt/AccessToken.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jwt/AccessToken.js b/lib/jwt/AccessToken.js index 44054db27f..e6a4f7e28d 100644 --- a/lib/jwt/AccessToken.js +++ b/lib/jwt/AccessToken.js @@ -249,7 +249,7 @@ _.extend(AccessToken.prototype, { } var grants = {}; - if (_.isInteger(this.identity) || _.isString(this.identity)) { grants.identity = String(this.identity); }; + if (_.isInteger(this.identity) || _.isString(this.identity)) { grants.identity = String(this.identity); } _.each(this.grants, function(grant) { grants[grant.key] = grant.toPayload();