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

Added token.verify and deprecated idToken.verify #49

Merged
merged 6 commits into from
Oct 27, 2016

Conversation

lboyette-okta
Copy link
Contributor

Resolves: OKTA-99715

In the process of deprecating the idToken.* methods, we weren't able to deprecate idToken.verify, because we didn't have a token.verify. Unlike idToken.verify, token.verify takes a fully parsed idToken, not the base64Url idToken string.

Additionally, now that we have caching, we can cache the jwks keys, so can check the signatures of idTokens often. Note: signature validation only works on browsers that support crypto.subtle.

@rchild-okta @magizh-okta

@lboyette-okta lboyette-okta force-pushed the lb-99715-idToken-validation branch from 403c97d to ccd2b32 Compare October 21, 2016 02:40
var jwt = decodeToken(token.idToken);

// Standard claim validation
oauthUtil.validateClaims(sdk, jwt.payload, token.clientId, token.issuer, nonce);
Copy link
Contributor

Choose a reason for hiding this comment

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

We dont expect validateClaims return any info before we proceed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validateClaims is a synchronous method that throws errors. validateClaims could be renamed to assertClaims, but it does additional validation that makes the term "assert" feel inaccurate.

.then(function(res) {
expect(res).toEqual(tokens.standardIdTokenParsed);
})
.fail(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

would fail even be hit since it is a success?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally it wouldn't, hence expect('not to be hit').toEqual(true);. If, for some reason, the id_token doesn't validate properly, we'll know.

Copy link
Contributor

@magizh-okta magizh-okta left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@magizh-okta
Copy link
Contributor

@rc @lboyette-okta do we have a way to test these changes against a backend and putting up a screencast or at least make sure the js changes work fine when integrated.

@lboyette-okta
Copy link
Contributor Author

@magizh-okta I'm testing locally, but the end-to-end tests in the okta-signin-widget will cover most of these changes (mostly just validating any id_token when it's created). We have an open ticket to create end-to-end tests in this repo.

@lboyette-okta lboyette-okta force-pushed the lb-99715-idToken-validation branch from ee24904 to 79c0759 Compare October 25, 2016 00:09
@@ -21,6 +23,9 @@ function verifyToken(idToken, key) {
var extractable = true;
var usages = ['verify'];

// https://connect.microsoft.com/IE/feedback/details/2242108/webcryptoapi-importing-jwk-with-use-field-fails
delete key.use;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a metadata tag that specifies the intent of how the key should be used. It's not necessary to properly verify the key's signature, per @yuliu-okta.

@lboyette-okta lboyette-okta force-pushed the lb-99715-idToken-validation branch 2 times, most recently from edc1a29 to e1b54d1 Compare October 25, 2016 01:00
Copy link
Contributor

@rchild-okta rchild-okta left a comment

Choose a reason for hiding this comment

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

Overall looks great, but have the one comment about using "global" state outside of a promise chain.

if (!tokenDict['token'] && !tokenDict['id_token']) {
throw new AuthSdkError('Unable to parse OAuth flow response');
}
if (!tokenDict['token'] && !tokenDict['id_token']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big fan of tracking the tokenDict state outside of the promise chain approach. Couple alternatives:

  1. (preferred) Don't worry about response format in the preceding block. Always do the checks, and return an array of the tokens that you've extracted. In this block, just do an array sort on the tokens (by the tokenTypes), or return the token itself if the tokenType is not an array.
  2. Create a new tokenDict in the preceding promise block, and then return that, and accept it as an argument here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why 1 is preferred over 2. To do the sorting of the tokens (and checking for the presence of an idToken or accessToken), it seems more reasonable to return a tokenDict and build the array of tokens in this block.

@lboyette-okta lboyette-okta force-pushed the lb-99715-idToken-validation branch from aeec884 to 1672f66 Compare October 26, 2016 23:10
Copy link
Contributor

@rchild-okta rchild-okta left a comment

Choose a reason for hiding this comment

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

lgtm (pending removing filter) 🚀

@lboyette-okta lboyette-okta force-pushed the lb-99715-idToken-validation branch from d551bfa to 0454de8 Compare October 27, 2016 16:58
@lboyette-okta lboyette-okta merged commit 83f2675 into master Oct 27, 2016
@jmelberg-okta jmelberg-okta deleted the lb-99715-idToken-validation branch April 23, 2018 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants