Skip to content

Add a callback for background token refresh outcomes#6099

Open
neha-bhargava wants to merge 1 commit into
nebharg/3682147-failure-metadatafrom
nebharg/3682729-background-refresh-callback
Open

Add a callback for background token refresh outcomes#6099
neha-bhargava wants to merge 1 commit into
nebharg/3682147-failure-metadatafrom
nebharg/3682729-background-refresh-callback

Conversation

@neha-bhargava

Copy link
Copy Markdown
Contributor

Proactive (background) token refresh is fire-and-forget: once the caller has a cached token, MSAL refreshes it on a background thread and the outcome is invisible from the outside. This adds an opt-in callback so that path can be observed - e.g. for telemetry parity during the SEAL -> MSAL migration.

  • New OnBackgroundTokenRefreshCompleted(Func<ExecutionResult, Task>) on the confidential client and managed identity builders (experimental).
  • On success the callback gets the AuthenticationResult; on failure it gets the exception, with the HTTP duration and cache-refresh reason on its AuthenticationResultMetadata.
  • Background refresh doesn't go through RunAsync, so the failure metadata is filled in from apiEvent in ProcessFetchInBackground.

Stacked on #6096 (which adds AuthenticationResultMetadata to MsalException) and targets that branch, so please review it after #6096. Work item 3682729.

Proactive (background) refresh is fire-and-forget, so callers can't see whether
it succeeded, how long it took, or why it failed. This adds an opt-in callback
(confidential client + managed identity) that hands back the AuthenticationResult
on success or the exception on failure - with the HTTP duration and cache-refresh
reason attached, so telemetry layers can report on this path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@neha-bhargava neha-bhargava requested a review from a team as a code owner July 1, 2026 19:19
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