Skip to content

Unified cache #418

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

Closed
wants to merge 2 commits into from
Closed

Unified cache #418

wants to merge 2 commits into from

Conversation

nehaagrawal
Copy link
Contributor

Unified cache first commit

reject(Constants_1.ErrorCodes.userLoginError + "|" + Constants_1.ErrorDescription.userLoginError);
return;
}
//if user didn't passes the login_hint and adal's idtoken is present and no userobject, user the login_hint gfrom adal's idToken
else if (!userObject_1 && !extraQueryParameters && !Utils_1.Utils.isEmpty(adalIdToken)) {
Copy link
Member

Choose a reason for hiding this comment

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

so, if any extraQueryParameters is present, adal id_token will be skipped? What if it's something like slice=testslice?

Copy link
Contributor Author

@nehaagrawal nehaagrawal Sep 12, 2018

Choose a reason for hiding this comment

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

I will remove the !extraQueryParameters from this condition. Just wanted to mention that all your review comments are on the generated code, The actual code sits in src/UserAgentApplication.ts

@@ -2577,13 +2587,22 @@ var UserAgentApplication = /** @class */ (function () {
}
var scope_1 = scopes.join(" ").toLowerCase();
var userObject_1 = user ? user : _this.getUser();
if (!userObject_1) {
var adalIdToken = _this._cacheStorage.getItem(Constants_1.Constants.adalIdToken);
Copy link
Member

Choose a reason for hiding this comment

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

Should it be responsibility of getUser to check for both MSAL and ADAL id tokens and create user? I'd prefer this method to not have the responsibility of tracking ADAL id token.

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 agree. When I created this PR, I made the changes for both option 2(don't change getUser()) and option 3(create MSAL object from adal's idToken). I just wanted to demonstrate how the changes will look like if we go with one option or the other. Since we are going ahead with option 3, I don't need this code.

@@ -2577,13 +2587,22 @@ var UserAgentApplication = /** @class */ (function () {
}
var scope_1 = scopes.join(" ").toLowerCase();
var userObject_1 = user ? user : _this.getUser();
if (!userObject_1) {
var adalIdToken = _this._cacheStorage.getItem(Constants_1.Constants.adalIdToken);
if (!userObject_1 && (extraQueryParameters && (extraQueryParameters.indexOf('login_hint') == -1 || extraQueryParameters.indexOf('sid') == -1)) && Utils_1.Utils.isEmpty(adalIdToken)) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider moving this check out to a variable or helper function.

(extraQueryParameters && (extraQueryParameters.indexOf('login_hint') == -1 || extraQueryParameters.indexOf('sid') == -1))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

else if (!userObject_1 && !extraQueryParameters && !Utils_1.Utils.isEmpty(adalIdToken)) {
var idTokenObject = Utils_1.Utils.extractIdToken(adalIdToken);
console.log("ADAL's idToken exists. Extracting login information from ADAL's idToken ");
extraQueryParameters = "&login_hint=" + idTokenObject.upn;
Copy link
Member

Choose a reason for hiding this comment

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

There's no guarantee that upn will be there in AAD v1 id_token. Consider adding a check to verify that upn is there.

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 code will be go away anyhow since this was added for option #2 and we are going ahead with option #3.

var authenticationRequest_1;
var newAuthority = authority ? AuthorityFactory_1.AuthorityFactory.CreateInstance(authority, _this.validateAuthority) : _this.authorityInstance;
if (Utils_1.Utils.compareObjects(userObject_1, _this.getUser())) {
var msalIdToken = _this._cacheStorage.getItem(Constants_1.Constants.idTokenKey);
if (Utils_1.Utils.compareObjects(userObject_1, _this.getUser()) && !Utils_1.Utils.isEmpty(msalIdToken)) { //TODO revisit this change if getUser() is not null
Copy link
Member

Choose a reason for hiding this comment

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

What if we have adal id token, but not msal id token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will go to the else block and get both idToken and accesstoken. Notice that the responsetype is idtoken and token
else {
authenticationRequest = new AuthenticationRequestParameters(newAuthority, this.clientId, scopes, ResponseTypes.id_token_token, this._redirectUri, this._state);
}

this._user = User_1.User.createUser(idToken, clientInfo, this.authority);
return this._user;
var adalIdToken = this._cacheStorage.getItem(Constants_1.Constants.adalIdToken);
if (!Utils_1.Utils.isEmpty(adalIdToken)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to first check for msal id token. we should only fallback to adal id token, if msal one is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If MSAL's idtoken exists then this._user object will be present and it will return before only. At this line

if (this._user) {
return this._user;
}

clientInfoObject["utid"] = utid;
var rawClientInfo = Utils_1.Utils.base64EncodeStringUrlSafe(JSON.stringify(clientInfoObject));
var clientInfo = new ClientInfo_1.ClientInfo(rawClientInfo);
this._user = User_1.User.createUser(idToken, clientInfo, this.authority);
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't return adal id token for msal user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have agreed on passing null/empty for unified cache. I will make this change.

@pkanher617 pkanher617 deleted the na/Unified_cache branch February 25, 2019 19:08
@pkanher617 pkanher617 restored the na/Unified_cache branch February 25, 2019 19:08
@pkanher617 pkanher617 deleted the na/Unified_cache branch February 25, 2019 19:08
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.

2 participants