Skip to content
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

Fixes missing identity value in token when it's not a string #484

Merged
merged 3 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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