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

Add suggested cache key for confidential client scenarios #1908

Merged
merged 6 commits into from
Jul 2, 2020

Conversation

jennyf19
Copy link
Collaborator

@jennyf19 jennyf19 commented Jun 27, 2020

This is for #1902 for confidential client scenarios, and has more info on the issue.

[ ] OBO should use the AT hash as the cache key, because the claims in the AT can change, so we use the AT directly to determine the cache key so the right AT is used.

[ ] Client credentials uses {client_id} + "_AppTokenCache", as it's using the app token cache, so it needs the token based on the client id. MS Identity Web suffixes it w/"_AppTokenCache", so we'd like to keep this pattern to not break current customers.

[ ] all other confidential client flows (including silent) use the home account id, as the key, because there is a user account.

In order to make the changes in MS Identity Web, we'd need to have this addition included in a nuget package. We have a deadline of July 6 on our end. cc: @jmprieur @henrik-me

@jennyf19 jennyf19 requested a review from bgavrilMS June 27, 2020 17:42
@@ -141,6 +143,7 @@ public async Task ConfidentialClientWithCertificateTestAsync()
MsalAssert.AssertAuthResult(authResult);
appCacheRecorder.AssertAccessCounts(2, 1);
Assert.IsTrue(appCacheRecorder.LastNotificationArgs.IsApplicationCache);
Assert.AreEqual(AppCacheKey, appCacheRecorder.LastNotificationArgs.SuggestedCacheKey);
Copy link
Member

@bgavrilMS bgavrilMS Jun 29, 2020

Choose a reason for hiding this comment

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

Integration tests seem to only cover AcquireTokenForClient and OBO, but not AcquireTokenSilent.
We need some unit test coverage as well - should be easy to update some existing tests for Client Creds and OBO. For AcquireTokenSilent as well. For GetAccount I think you need a dedicated unit test. #Resolved

new AcquireTokenCommonParameters(),
requestContext));
var accountsFromCache = await GetAccountsFromCacheAsync(homeAccountId, requestContext).ConfigureAwait(false);
IEnumerable<IAccount> cacheAndBrokerAccounts =
Copy link
Member

@bgavrilMS bgavrilMS Jun 29, 2020

Choose a reason for hiding this comment

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

Small refactoring of this method, not related to your work. #Resolved

/// <item>null for all other calls, such as PubliClientApplication calls, which should persist the token cache in a single location</item>
/// </list>
/// </summary>
public string SuggestedCacheKey { get; }
Copy link
Member

Choose a reason for hiding this comment

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

I added comments, please review. (CC @jmprieur )

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

Needs more unit testing.

Assert.AreEqual(homeAccId, cacheAccess.LastNotificationArgs.SuggestedCacheKey);

// Act
await app.AcquireTokenSilent(TestConstants.s_scope, accountById.Username).ExecuteAsync().ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

@jmprieur @jennyf19 - please see this test case - ATS with login hint is not able to suggest a token cache key, because MSAL needs to load all accounts and filter by username. Loading all accounts triggers a cache read.

If this is not acceptable, we should discuss.

Copy link
Contributor

@jmprieur jmprieur Jul 1, 2020

Choose a reason for hiding this comment

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

Yes, @bgavrilMS : we need to discuss.
this API, as well as GetAccountsAsync() don't make sense for confidential client applications.
but this is a different problem. I was even thinking of not proposing them any longer for CCA (this would be a breaking change)

Copy link
Member

Choose a reason for hiding this comment

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

We can duplicate GetAccountsAsync methods so that they exist on both PCA and CCA. And then Obsolete them on CCA. But why would I not want to do GetAccountsAsync on a cca?

@jennyf19
Copy link
Collaborator Author

jennyf19 commented Jul 1, 2020

@bgavrilMS the tests don't seem to pass. i notice the same for your PR...its that expected?

@bgavrilMS
Copy link
Member

@jennyf19 - on my PR I have a unit test failing, I'll take care of this. On this PR some unrelated integration tests are failing. Let me rerun the build.

@jennyf19
Copy link
Collaborator Author

jennyf19 commented Jul 1, 2020

@bgavrilMS sounds good. go ahead and merge whenever you want. ty

@bgavrilMS bgavrilMS merged commit 152af23 into master Jul 2, 2020
@bgavrilMS bgavrilMS deleted the jennyf/cacheKey branch July 2, 2020 13:18
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