Skip to content

Expose MSAL's OnBackgroundTokenRefreshCompleted callback through Id.Web#3973

Open
neha-bhargava wants to merge 1 commit into
masterfrom
nebharg/idweb-background-refresh-callback
Open

Expose MSAL's OnBackgroundTokenRefreshCompleted callback through Id.Web#3973
neha-bhargava wants to merge 1 commit into
masterfrom
nebharg/idweb-background-refresh-callback

Conversation

@neha-bhargava

Copy link
Copy Markdown
Contributor

What

Exposes MSAL's OnBackgroundTokenRefreshCompleted proactive-refresh callback through Id.Web, for both confidential client and managed identity apps.

  • New TokenAcquisitionExtensionOptions.OnBackgroundTokenRefreshCompleted (Func<ExecutionResult, Task>?). It's a code-configured delegate (not JSON-bindable), consistent with the other extensibility hooks on this type.
  • Wired onto the CCA builder (BuildConfidentialClientApplicationAsync) and the managed identity builder (BuildManagedIdentityApplication). The MI builder now calls WithExperimentalFeatures() 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 : RequestBase inherits foreground metadata population, and MI uses the same SilentRequestHelper.ProcessFetchInBackground, so the ExecutionResult carries 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 the WithExperimentalFeatures() requirement.
  • 51/51 pass across affected classes; net8.0 + net472 build clean (PublicAPI analyzer green).

Related

@neha-bhargava
neha-bhargava requested a review from a team as a code owner July 23, 2026 21:30
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
neha-bhargava force-pushed the nebharg/idweb-background-refresh-callback branch from 2c49f5c to df2c05f Compare July 24, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant