Skip to content

Commit 44b8085

Browse files
isra-felNickcandymsJinLei
authored
disable token cache for service principal (#20336)
Co-authored-by: NanxiangLiu <[email protected]> Co-authored-by: Jin Lei <[email protected]>
1 parent fcd4743 commit 44b8085

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22-
* Enabled caching tokens when logging in with a service principal or client assertion. [#20013]
23-
- This could reduce extra network traffic and improve performance.
24-
- It also fixed the incorrectly short lifespan of tokens.
22+
* Enabled caching tokens when logging in with a client assertion. This fixed the incorrectly short lifespan of tokens.
2523
* Upgraded target framework of Microsoft.Identity.Client to net461 [#20189]
2624
* Stored `ServicePrincipalSecret` and `CertificatePassword` into `AzKeyStore`.
2725
* Updated the reference of Azure PowerShell Common to 1.3.65-preview.

src/Accounts/Authenticators/ServicePrincipalAuthenticator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ public override Task<IAccessToken> Authenticate(AuthenticationParameters paramet
4343
var authority = spParameters.Environment.ActiveDirectoryAuthority;
4444

4545
var requestContext = new TokenRequestContext(scopes);
46-
var tokenCachePersistenceOptions = spParameters.TokenCacheProvider.GetTokenCachePersistenceOptions();
46+
// var tokenCachePersistenceOptions = spParameters.TokenCacheProvider.GetTokenCachePersistenceOptions();
4747
AzureSession.Instance.TryGetComponent(nameof(AzureCredentialFactory), out AzureCredentialFactory azureCredentialFactory);
4848

4949
var options = new ClientCertificateCredentialOptions()
5050
{
51-
TokenCachePersistenceOptions = tokenCachePersistenceOptions, // allows MSAL to cache access tokens
51+
// commented due to https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/3218
52+
// todo: investigate splitting user token cache and app token cache
53+
// TokenCachePersistenceOptions = tokenCachePersistenceOptions, // allows MSAL to cache access tokens
5254
AuthorityHost = new Uri(authority),
5355
SendCertificateChain = spParameters.SendCertificateChain ?? default(bool)
5456
};
@@ -67,7 +69,7 @@ public override Task<IAccessToken> Authenticate(AuthenticationParameters paramet
6769
//Service principal with secret
6870
var csOptions = new ClientSecretCredentialOptions()
6971
{
70-
TokenCachePersistenceOptions = tokenCachePersistenceOptions, // allows MSAL to cache access tokens
72+
// TokenCachePersistenceOptions = tokenCachePersistenceOptions, // allows MSAL to cache access tokens
7173
AuthorityHost = new Uri(authority)
7274
};
7375
tokenCredential = azureCredentialFactory.CreateClientSecretCredential(tenantId, spParameters.ApplicationId, spParameters.Secret, csOptions);

0 commit comments

Comments
 (0)