Expose MSAL's OnBackgroundTokenRefreshCompleted callback through Id.Web#3973
Open
neha-bhargava wants to merge 1 commit into
Open
Expose MSAL's OnBackgroundTokenRefreshCompleted callback through Id.Web#3973neha-bhargava wants to merge 1 commit into
neha-bhargava wants to merge 1 commit into
Conversation
Adds a code-configured OnBackgroundTokenRefreshCompleted delegate on TokenAcquisitionExtensionOptions and wires it onto both the confidential client and managed identity MSAL app builders, so apps can observe the outcome (latency, failures, metadata) of fire-and-forget proactive token refreshes for telemetry. The managed identity builder now enables experimental features so the callback's experimental gate is satisfied. Work item: 3697080 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d296b5aa-33db-4934-a697-cdf1c1999e09
neha-bhargava
force-pushed
the
nebharg/idweb-background-refresh-callback
branch
from
July 24, 2026 23:14
2c49f5c to
df2c05f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Exposes MSAL's
OnBackgroundTokenRefreshCompletedproactive-refresh callback through Id.Web, for both confidential client and managed identity apps.TokenAcquisitionExtensionOptions.OnBackgroundTokenRefreshCompleted(Func<ExecutionResult, Task>?). It's a code-configured delegate (not JSON-bindable), consistent with the other extensibility hooks on this type.BuildConfidentialClientApplicationAsync) and the managed identity builder (BuildManagedIdentityApplication). The MI builder now callsWithExperimentalFeatures()so MSAL's experimental gate for the callback is satisfied (the CCA builder already did).Why
Proactive (background) token refresh runs on a fire-and-forget thread after the caller already received a cached token, so its outcome — latency, failures, and token-acquisition metadata — is otherwise unobservable. This surfaces it for telemetry. Requested for SEAL 21 outbound telemetry.
Metadata parity (MI == CCA)
No MSAL change needed.
ManagedIdentityAuthRequest : RequestBaseinherits foreground metadata population, and MI uses the sameSilentRequestHelper.ProcessFetchInBackground, so theExecutionResultcarries metadata on both success and failure for MI exactly as for CCA.Tests
GetOrBuildConfidentialClientApplication_WithBackgroundRefreshCallback_BuildsApp— CCA build path wires the callback without MSAL throwing.ManagedIdentity_WithBackgroundRefreshCallback_BuildsAndAcquiresToken— MI acquires a token with the callback configured; guards theWithExperimentalFeatures()requirement.Related