Skip to content

Commit

Permalink
Disable the token cache for FederationToken login flow if Az.Accounts…
Browse files Browse the repository at this point in the history
… is set to in memory token cache option

Workaround #22628
  • Loading branch information
msJinLei committed Mar 20, 2024
1 parent c2a615c commit 652fad1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Disable the token cache for FederationToken login flow if Az.Accounts is set to in memory token cache option as a workaround for #22628.
* Added `AsSecureString` to `Get-AzAccessToken` to convert the returned token to SecureString [#24190].
* Upgraded Azure.Core to 1.37.0.

Expand Down
6 changes: 5 additions & 1 deletion src/Accounts/Authenticators/ClientAssertionAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public override Task<IAccessToken> Authenticate(AuthenticationParameters paramet
var options = new ClientAssertionCredentialOptions()
{
AuthorityHost = new Uri(authority),
TokenCachePersistenceOptions = spParameters.TokenCacheProvider.GetTokenCachePersistenceOptions()
};
if (!(spParameters.TokenCacheProvider.GetTokenCachePersistenceOptions() is InMemoryTokenCacheOptions))
{
options.TokenCachePersistenceOptions = spParameters.TokenCacheProvider.GetTokenCachePersistenceOptions();
}

options.Diagnostics.IsTelemetryEnabled = false; // disable telemetry to avoid error thrown from Azure.Core that AssemblyInformationalVersion is null
TokenCredential tokenCredential = new ClientAssertionCredential(tenantId, spParameters.ClientId, () => GetClientAssertion(spParameters), options);
string parametersLog = $"- ClientId:'{spParameters.ClientId}', TenantId:'{tenantId}', ClientAssertion:'***' Scopes:'{string.Join(",", scopes)}'";
Expand Down

0 comments on commit 652fad1

Please sign in to comment.