-
Notifications
You must be signed in to change notification settings - Fork 365
Enhancing Token Refresh Control in MSAL: Introducing .WithAccessTokenSha256ToRefresh() in AcquireTokenForClient Flows #5179
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Do we plan to implement the managed identity part of functionality in a different PR? As this PR currently stands, it is not sufficient to "fix #5111", so, better remove the first line in the PR description and remove #5111 from "Successfully merging this pull request may close these issues."
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
bb24951
to
fe2a0a2
Compare
@rayluo @Robbie-Microsoft can I get a review from you as well please |
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality wise, this PR shall work. Adding a couple of minor comments below, but overall LGTM.
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ConfidentialClientApplicationTests.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
...dentity.Client/Extensibility/RP/AcquireTokenForClientParameterBuilderForResourceProviders.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Show resolved
Hide resolved
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ConfidentialClientApplicationTests.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with comments. Let's discuss about telemetry separately.
fcec87b
to
6902b17
Compare
…redentialRequest.cs Co-authored-by: Bogdan Gavril <bogavril@microsoft.com>
…redentialRequest.cs Co-authored-by: Neha Bhargava <61847233+neha-bhargava@users.noreply.github.com>
92b760e
to
f32c808
Compare
All comments addressed and removed experimental flags check from the tests, as we are GA'ing the API. |
(!string.IsNullOrEmpty(AuthenticationRequestParameters.Claims) && | ||
string.IsNullOrEmpty(_clientParameters.AccessTokenHashToRefresh)); | ||
|
||
if (skipCache) | ||
{ | ||
AuthenticationRequestParameters.RequestContext.ApiEvent.CacheInfo = CacheRefreshReason.ForceRefreshOrClaims; | ||
logger.Info("[ClientCredentialRequest] Skipped looking for a cached access token because ForceRefresh or Claims were set."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.Info("[ClientCredentialRequest] Skipped looking for a cached access token because ForceRefresh or Claims were set."); | |
logger.Info("[ClientCredentialRequest] Skipped looking for a cached access token because either of ForceRefresh, Claims or AccessTokenHashToRefresh were set."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Actually, the new change was still inaccurate. The accurate statement shall be "skipped ... cache ... because either ForceRefresh was set, or Claims was set without AccessTokenHashToRefresh".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being addressed in #5201
…redentialRequest.cs Co-authored-by: Neha Bhargava <61847233+neha-bhargava@users.noreply.github.com>
Fixes #5111
Specification - https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/main/docs/msiv1_token_revocation.md
Changes proposed in this request
This pull request includes several changes to enhance token acquisition and revocation capabilities in the MSAL library. The most important changes focus on adding support for token hash-based refresh, improving cache handling, and updating error handling.
Enhancements to Token Acquisition and Revocation:
WithAccessTokenSha256ToRefresh
to theAcquireTokenForClientParameterBuilder
for configuring the SDK to bypass the cache for a specific token based on its SHA-256 hash.AccessTokenHashToRefresh
inAcquireTokenForClientParameters
to store the hash of the token to be refreshed.ClientCredentialRequest
to handle token hash-based refresh logic, including checking the cache for matching tokens and bypassing the cache if necessary. [1] [2] [3]Error Handling Improvements:
ForceRefreshNotCompatibleWithTokenHash
to indicate that force refresh and token hash cannot be used together. [1] [2] [3]Internal Code Changes:
Parameters
property inAcquireTokenForClientParameterBuilder
from private to internal.AcquireTokenForClientParameterBuilder
to throw an exception if both force refresh and token hash are used together.Documentation Updates:
docs/msiv1_token_revocation.md
.These changes collectively improve the flexibility and robustness of token handling in the MSAL library.
Testing
unit tests
Performance impact
none
Documentation