-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Background Session Refresh #8252
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
base: dev
Are you sure you want to change the base?
Conversation
|
@copilot add PR description |
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.
Pull request overview
This PR adds a background SSO feature that automatically refreshes tokens after successful interactive authentication. When enabled via the new enableBackgroundSSO configuration option, MSAL will fire a fire-and-forget ssoSilent call after handleRedirectPromise and acquireTokenPopup complete successfully.
Changes:
- Added new
enableBackgroundSSOconfiguration option (defaults to false) - Implemented fire-and-forget background
ssoSilentcalls after interactive authentication - Added comprehensive telemetry tracking with new
BackgroundSsoSilentperformance event
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/msal-common/src/telemetry/performance/PerformanceEvent.ts | Added BackgroundSsoSilent performance event and telemetry abbreviation for tracking background SSO calls |
| lib/msal-browser/src/config/Configuration.ts | Added enableBackgroundSSO configuration option to BrowserAuthOptions with default value of false |
| lib/msal-browser/src/controllers/StandardController.ts | Implemented bkgdSsoSilent method using setTimeout for non-blocking execution, integrated into handleRedirectPromise and acquireTokenPopup flows |
| lib/msal-browser/test/app/PublicClientApplication.spec.ts | Added comprehensive test coverage for background SSO in both success and failure scenarios, feature flag validation, and fire-and-forget behavior verification |
| change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6.json | Beachball change file for msal-common package |
| change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d7976.json | Beachball change file for msal-browser package |
change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6.json
Outdated
Show resolved
Hide resolved
change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d7976.json
Outdated
Show resolved
Hide resolved
change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6.json
Outdated
Show resolved
Hide resolved
change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d7976.json
Outdated
Show resolved
Hide resolved
….json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…6.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds fire-and-forget `ssoSilent` calls after interactive authentication
(`acquireTokenPopup`, `handleRedirectPromise`) to proactively refresh
tokens in the background.
## Changes
- **Configuration**: Added `enableBackgroundSSO` boolean to
`BrowserAuthOptions` (default: `false`)
- **Implementation**: `bkgdSsoSilent()` method uses `setTimeout` to
defer SSO call until after interactive result returns, preventing
blocking
- **Telemetry**: New `BackgroundSsoSilent` performance event tracks
parent API, success/failure, and token sizes
## Usage
```typescript
const msalConfig = {
auth: {
clientId: "your-client-id",
authority: "https://login.microsoftonline.com/common",
enableBackgroundSSO: true // Enable background token refresh
}
};
const msalInstance = new PublicClientApplication(msalConfig);
// After popup or redirect completes, background ssoSilent fires automatically
const result = await msalInstance.acquireTokenPopup(request);
// Background SSO initiated - tokens refreshed silently without blocking return
```
Background calls fail silently with warning logs - they don't affect the
main authentication flow.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d7976.json
Outdated
Show resolved
Hide resolved
change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6.json
Outdated
Show resolved
Hide resolved
| */ | ||
| async refreshSession(request: SsoSilentRequest): Promise<boolean> { | ||
| this.performanceClient.addQueueMeasurement( | ||
| PerformanceEvents.SilentIframeClientAcquireToken, |
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.
Is there a need to make this synthentic, to not interfere in regular telemetry? If this is only for observability, may be we are okay? Confirm this.
This PR adds a background session refresh that automatically refreshes tokens after successful interactive authentication. When enabled via the new enableBackgroundSSO configuration option, MSAL will fire a fire-and-forget bkdgRefresh call after handleRedirectPromise and acquireTokenPopup complete successfully.
Changes: