Skip to content

Commit

Permalink
pass the accountId to the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyf19 committed Jun 26, 2020
1 parent a3b2015 commit d56111c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private async Task RefreshCacheForReadOperationsAsync(CacheEvent.TokenTypes cach
{
if (!_cacheRefreshedForRead) // double check locking
{

using (_requestParams.RequestContext.CreateTelemetryHelper(cacheEvent))
{
TokenCacheNotificationArgs args = new TokenCacheNotificationArgs(
Expand All @@ -110,7 +109,7 @@ private async Task RefreshCacheForReadOperationsAsync(CacheEvent.TokenTypes cach
_requestParams.Account,
hasStateChanged: false,
TokenCacheInternal.IsApplicationCache,
_requestParams.SuggestedCacheKey);
_requestParams.Account?.HomeAccountId?.Identifier);

try
{
Expand Down
23 changes: 17 additions & 6 deletions src/client/Microsoft.Identity.Client/ClientApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ internal ClientApplicationBase(ApplicationConfiguration config)
/// Returns all the available <see cref="IAccount">accounts</see> in the user token cache for the application.
/// </summary>
public async Task<IEnumerable<IAccount>> GetAccountsAsync()
{
return await GetAccountsWithHomeAccountIdAsync(null).ConfigureAwait(false);
}

/// <summary>
/// Returns all the available <see cref="IAccount">accounts</see> in the user token cache for the application.
/// </summary>
public async Task<IEnumerable<IAccount>> GetAccountsWithHomeAccountIdAsync(string homeAccountId)
{
RequestContext requestContext = CreateRequestContext(Guid.NewGuid());
IEnumerable<IAccount> localAccounts = Enumerable.Empty<IAccount>();
Expand All @@ -89,14 +97,17 @@ public async Task<IEnumerable<IAccount>> GetAccountsAsync()
}
else
{
var authParameters = new AuthenticationRequestParameters(
ServiceBundle,
UserTokenCacheInternal,
new AcquireTokenCommonParameters(),
requestContext);

authParameters.Account = new Account(homeAccountId, null, Authority);
// a simple session consisting of a single call
CacheSessionManager cacheSessionManager = new CacheSessionManager(
UserTokenCacheInternal,
new AuthenticationRequestParameters(
ServiceBundle,
UserTokenCacheInternal,
new AcquireTokenCommonParameters(),
requestContext));
authParameters);

localAccounts = await cacheSessionManager.GetAccountsAsync(Authority).ConfigureAwait(false);
}
Expand Down Expand Up @@ -150,7 +161,7 @@ public async Task<IEnumerable<IAccount>> GetAccountsAsync(string userFlow)
/// </param>
public async Task<IAccount> GetAccountAsync(string accountId)
{
var accounts = await GetAccountsAsync().ConfigureAwait(false);
var accounts = await GetAccountsWithHomeAccountIdAsync(accountId).ConfigureAwait(false);
return accounts.FirstOrDefault(account => account.HomeAccountId.Identifier.Equals(accountId, StringComparison.OrdinalIgnoreCase));
}

Expand Down

0 comments on commit d56111c

Please sign in to comment.