diff --git a/src/Microsoft.Identity.Web/TokenAcquisition.cs b/src/Microsoft.Identity.Web/TokenAcquisition.cs
index 728eae8c9..9ee4cae20 100644
--- a/src/Microsoft.Identity.Web/TokenAcquisition.cs
+++ b/src/Microsoft.Identity.Web/TokenAcquisition.cs
@@ -287,7 +287,7 @@ public async Task RemoveAccountAsync(RedirectContext context)
await app.RemoveAsync(b2cAccount).ConfigureAwait(false);
}
- _tokenCacheProvider?.ClearAsync().ConfigureAwait(false);
+ _tokenCacheProvider?.ClearAsync(_microsoftIdentityOptions.ClientId).ConfigureAwait(false);
}
else
@@ -304,7 +304,7 @@ public async Task RemoveAccountAsync(RedirectContext context)
if (account != null)
{
await app.RemoveAsync(account).ConfigureAwait(false);
- _tokenCacheProvider?.ClearAsync().ConfigureAwait(false);
+ _tokenCacheProvider?.ClearAsync(_microsoftIdentityOptions.ClientId).ConfigureAwait(false);
}
}
}
diff --git a/src/Microsoft.Identity.Web/TokenCacheProviders/Distributed/MsalDistributedTokenCacheAdapter.cs b/src/Microsoft.Identity.Web/TokenCacheProviders/Distributed/MsalDistributedTokenCacheAdapter.cs
index fedea68d3..4bb7acb09 100644
--- a/src/Microsoft.Identity.Web/TokenCacheProviders/Distributed/MsalDistributedTokenCacheAdapter.cs
+++ b/src/Microsoft.Identity.Web/TokenCacheProviders/Distributed/MsalDistributedTokenCacheAdapter.cs
@@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
+using System.Threading.Tasks;
namespace Microsoft.Identity.Web.TokenCacheProviders.Distributed
{
@@ -32,11 +31,10 @@ public class MsalDistributedTokenCacheAdapter : MsalAbstractTokenCacheProvider
///
///
///
- public MsalDistributedTokenCacheAdapter(IOptions microsoftIdentityOptions,
- IHttpContextAccessor httpContextAccessor,
+ public MsalDistributedTokenCacheAdapter(IHttpContextAccessor httpContextAccessor,
IDistributedCache memoryCache,
IOptions cacheOptions) :
- base(microsoftIdentityOptions, httpContextAccessor)
+ base(httpContextAccessor)
{
_distributedCache = memoryCache;
_cacheOptions = cacheOptions.Value;
diff --git a/src/Microsoft.Identity.Web/TokenCacheProviders/IMsalTokenCacheProvider .cs b/src/Microsoft.Identity.Web/TokenCacheProviders/IMsalTokenCacheProvider .cs
index 98cfa6366..b21b0679f 100644
--- a/src/Microsoft.Identity.Web/TokenCacheProviders/IMsalTokenCacheProvider .cs
+++ b/src/Microsoft.Identity.Web/TokenCacheProviders/IMsalTokenCacheProvider .cs
@@ -22,6 +22,6 @@ public interface IMsalTokenCacheProvider
/// Clear the cache
///
///
- Task ClearAsync();
+ Task ClearAsync(string clientId);
}
}
diff --git a/src/Microsoft.Identity.Web/TokenCacheProviders/InMemory/MsalMemoryTokenCacheProvider.cs b/src/Microsoft.Identity.Web/TokenCacheProviders/InMemory/MsalMemoryTokenCacheProvider.cs
index b79da8559..19a583752 100644
--- a/src/Microsoft.Identity.Web/TokenCacheProviders/InMemory/MsalMemoryTokenCacheProvider.cs
+++ b/src/Microsoft.Identity.Web/TokenCacheProviders/InMemory/MsalMemoryTokenCacheProvider.cs
@@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
+using System.Threading.Tasks;
namespace Microsoft.Identity.Web.TokenCacheProviders.InMemory
{
@@ -32,11 +31,10 @@ public class MsalMemoryTokenCacheProvider : MsalAbstractTokenCacheProvider
///
///
///
- public MsalMemoryTokenCacheProvider(IOptions microsoftIdentityOptions,
- IHttpContextAccessor httpContextAccessor,
+ public MsalMemoryTokenCacheProvider(IHttpContextAccessor httpContextAccessor,
IMemoryCache memoryCache,
IOptions cacheOptions) :
- base(microsoftIdentityOptions, httpContextAccessor)
+ base(httpContextAccessor)
{
_memoryCache = memoryCache;
_cacheOptions = cacheOptions.Value;
diff --git a/src/Microsoft.Identity.Web/TokenCacheProviders/MsalAbstractTokenCacheProvider.cs b/src/Microsoft.Identity.Web/TokenCacheProviders/MsalAbstractTokenCacheProvider.cs
index 2fccea8a7..c7398cb4d 100644
--- a/src/Microsoft.Identity.Web/TokenCacheProviders/MsalAbstractTokenCacheProvider.cs
+++ b/src/Microsoft.Identity.Web/TokenCacheProviders/MsalAbstractTokenCacheProvider.cs
@@ -1,9 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.Options;
using Microsoft.Identity.Client;
using System.IdentityModel.Tokens.Jwt;
using System.Threading.Tasks;
@@ -14,11 +12,6 @@ namespace Microsoft.Identity.Web.TokenCacheProviders
///
public abstract class MsalAbstractTokenCacheProvider : IMsalTokenCacheProvider
{
- ///
- /// Azure AD options
- ///
- protected readonly IOptions _microsoftIdentityOptions;
-
///
/// Http accessor
///
@@ -29,9 +22,8 @@ public abstract class MsalAbstractTokenCacheProvider : IMsalTokenCacheProvider
///
///
///
- protected MsalAbstractTokenCacheProvider(IOptions microsoftIdentityOptions, IHttpContextAccessor httpContextAccessor)
+ protected MsalAbstractTokenCacheProvider(IHttpContextAccessor httpContextAccessor)
{
- _microsoftIdentityOptions = microsoftIdentityOptions;
_httpContextAccessor = httpContextAccessor;
}
@@ -52,11 +44,11 @@ public Task InitializeAsync(ITokenCache tokenCache)
///
/// Cache key
///
- private string GetCacheKey(bool isAppTokenCache)
+ private string GetCacheKey(bool isAppTokenCache, string clientId)
{
if (isAppTokenCache)
{
- return $"{_microsoftIdentityOptions.Value.ClientId}_AppTokenCache";
+ return $"{clientId}_AppTokenCache";
}
else
{
@@ -81,7 +73,7 @@ private async Task OnAfterAccessAsync(TokenCacheNotificationArgs args)
// if the access operation resulted in a cache update
if (args.HasStateChanged)
{
- string cacheKey = GetCacheKey(args.IsApplicationCache);
+ string cacheKey = GetCacheKey(args.IsApplicationCache, args.ClientId);
if (!string.IsNullOrWhiteSpace(cacheKey))
{
await WriteCacheBytesAsync(cacheKey, args.TokenCache.SerializeMsalV3()).ConfigureAwait(false);
@@ -91,7 +83,7 @@ private async Task OnAfterAccessAsync(TokenCacheNotificationArgs args)
private async Task OnBeforeAccessAsync(TokenCacheNotificationArgs args)
{
- string cacheKey = GetCacheKey(args.IsApplicationCache);
+ string cacheKey = GetCacheKey(args.IsApplicationCache, args.ClientId);
if (!string.IsNullOrEmpty(cacheKey))
{
@@ -106,10 +98,10 @@ protected virtual Task OnBeforeWriteAsync(TokenCacheNotificationArgs args)
return Task.CompletedTask;
}
- public async Task ClearAsync()
+ public async Task ClearAsync(string clientId)
{
// This is a user token cache
- await RemoveKeyAsync(GetCacheKey(false)).ConfigureAwait(false);
+ await RemoveKeyAsync(GetCacheKey(false, clientId)).ConfigureAwait(false);
// TODO: Clear the cookie session if any. Get inspiration from
// https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/issues/240
diff --git a/src/Microsoft.Identity.Web/TokenCacheProviders/Session/MsalSessionTokenCacheProvider.cs b/src/Microsoft.Identity.Web/TokenCacheProviders/Session/MsalSessionTokenCacheProvider.cs
index 0d5df6f70..d0d4f92e9 100644
--- a/src/Microsoft.Identity.Web/TokenCacheProviders/Session/MsalSessionTokenCacheProvider.cs
+++ b/src/Microsoft.Identity.Web/TokenCacheProviders/Session/MsalSessionTokenCacheProvider.cs
@@ -2,10 +2,9 @@
// Licensed under the MIT License.
using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.Options;
+using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
-using Microsoft.Extensions.Logging;
namespace Microsoft.Identity.Web.TokenCacheProviders.Session
{
@@ -32,10 +31,9 @@ public class MsalSessionTokenCacheProvider : MsalAbstractTokenCacheProvider, IMs
private ILogger _logger;
public MsalSessionTokenCacheProvider(
- IOptions microsoftIdentityOptions,
IHttpContextAccessor httpContextAccessor,
ILogger logger) :
- base(microsoftIdentityOptions, httpContextAccessor)
+ base(httpContextAccessor)
{
_logger = logger;
}
diff --git a/tests/Microsoft.Identity.Web.Test.Common/TestHelpers/MsalTestTokenCacheProvider.cs b/tests/Microsoft.Identity.Web.Test.Common/TestHelpers/MsalTestTokenCacheProvider.cs
index 1b29c5563..95904f2ce 100644
--- a/tests/Microsoft.Identity.Web.Test.Common/TestHelpers/MsalTestTokenCacheProvider.cs
+++ b/tests/Microsoft.Identity.Web.Test.Common/TestHelpers/MsalTestTokenCacheProvider.cs
@@ -17,11 +17,10 @@ public class MsalTestTokenCacheProvider : MsalAbstractTokenCacheProvider
public int Count { get; internal set; }
public MsalTestTokenCacheProvider(
- IOptions microsoftIdentityOptions,
IHttpContextAccessor httpContextAccessor,
IMemoryCache memoryCache,
IOptions cacheOptions) :
- base(microsoftIdentityOptions, httpContextAccessor)
+ base(httpContextAccessor)
{
MemoryCache = memoryCache;
_cacheOptions = cacheOptions.Value;
diff --git a/tests/Microsoft.Identity.Web.Test.Integration/AcquireTokenForAppIntegrationTests.cs b/tests/Microsoft.Identity.Web.Test.Integration/AcquireTokenForAppIntegrationTests.cs
index 5f60e4d3d..51df6f760 100644
--- a/tests/Microsoft.Identity.Web.Test.Integration/AcquireTokenForAppIntegrationTests.cs
+++ b/tests/Microsoft.Identity.Web.Test.Integration/AcquireTokenForAppIntegrationTests.cs
@@ -96,7 +96,6 @@ private void InitializeTokenAcquisitionObjects()
IHttpContextAccessor httpContextAccessor = CreateMockHttpContextAccessor();
_msalTestTokenCacheProvider = new MsalTestTokenCacheProvider(
- microsoftIdentityOptions,
httpContextAccessor,
_provider.GetService(),
tokenOptions);