Skip to content

Commit

Permalink
Fixes missing identity value in token when it's not a string (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Dawidowski authored and childish-sambino committed Oct 18, 2019
1 parent 51318fb commit a235cbb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ config.js

### jsdoc dir ###
docs

### ide / editors ###
.vscode
2 changes: 1 addition & 1 deletion lib/jwt/AccessToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,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();
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/jwt/AccessToken.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a235cbb

Please sign in to comment.