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

Conversation

codedawi
Copy link
Contributor

@codedawi codedawi commented Oct 7, 2019

Fixes #438

Resolves missing identity value in token when it's not a string begin passed in the AccessToken constructor.

The specs of the issue ticket suggest throwing an error when identity is passed as an integer. Originally, I took this approach but I quickly realized this would cause breaking changes for anyone passing numeric values in identity option. I do not believe this is error worthy because simple converting the value to a string solves the down stream implication in the jwt.

 if (_.isInteger(options.identity)) { options.identity = new String(options.identity); };

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • I acknowledge that all my contributions will be made under the project's license.

@@ -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); };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather fix the check on line 252 below. Could it just be grants.identity = String(this.identity);?

@childish-sambino childish-sambino added difficulty: easy fix is easy in difficulty status: waiting for feedback waiting for feedback from the submitter type: community enhancement feature request not on Twilio's roadmap labels Oct 11, 2019
@codedawi
Copy link
Contributor Author

@childish-sambino yes makes sense to move it there. I left the original conditional statement checking _.isString and added _.isInteger with an "or" operator. When true, grants.identity = String(this.identity);

Copy link
Contributor

@childish-sambino childish-sambino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -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); };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Trailing semicolon not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing identity in token when not string
2 participants