-
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
Open
sameerag
wants to merge
24
commits into
dev
Choose a base branch
from
sso-post-interaction
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+999
−51
Open
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
311fc3f
Add a bakground ssoSilent call after interactive calls, with telemetry
sameerag 632c393
update the interactive APIs
sameerag 0a2f5e1
Change files
sameerag eb8df76
Update change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6…
sameerag ef600d9
Update change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d797…
sameerag fa1c809
Background SSO calls (#8253)
Copilot b0eac1a
Update lib/msal-browser/src/controllers/StandardController.ts
sameerag 4565ab7
Update lib/msal-browser/src/config/Configuration.ts
sameerag f1fff9d
Update change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d797…
sameerag b14dbe8
Update change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6…
sameerag 7626e80
Limit the sso to session refresh
sameerag e9a32f7
update apiExtractor
sameerag 7f283d7
Update lib/msal-browser/src/config/Configuration.ts
sameerag 64de352
Update lib/msal-browser/src/config/Configuration.ts
sameerag 4ee54c0
Update names
sameerag 1e24dcb
Update apiExtractor for msal-common
sameerag 827a6ff
Merge branch 'dev' into sso-post-interaction
sameerag e0f6b03
Merge branch 'dev' into sso-post-interaction
sameerag cd804d1
Update correlationId - change it to be a different one
sameerag 28cbf36
Address feedback
sameerag d29ef3d
Merge branch 'dev' into sso-post-interaction
konstantin-msft 6e7f446
Rename appropriately
sameerag 03a70d4
Rename config
sameerag 4e6c400
Merge branch 'dev' into sso-post-interaction
sameerag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-440d27b3-88ff-459d-883e-a675b66d7976.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Add a background ssoSilent call after interactive calls, with telemetry", | ||
| "packageName": "@azure/msal-browser", | ||
| "email": "sameera.gajjarapu@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-common-461989e8-10b5-48f1-91dd-836248c3fce6.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Add a background ssoSilent call after interactive calls, with telemetry", | ||
sameerag marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "packageName": "@azure/msal-common", | ||
| "email": "sameera.gajjarapu@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,6 +567,9 @@ export class StandardController implements IController { | |
| undefined, | ||
| result.account | ||
| ); | ||
|
|
||
| // Fire-and-forget ssoSilent to refresh tokens in background | ||
| this.bkgdSsoSilent(result, "handleRedirectPromise"); | ||
| } else { | ||
| /* | ||
| * Instrument an event only if an error code is set. Otherwise, discard it when the redirect response | ||
|
|
@@ -930,6 +933,10 @@ export class StandardController implements IController { | |
| undefined, | ||
| result.account | ||
| ); | ||
|
|
||
| // Fire-and-forget ssoSilent to refresh tokens in background | ||
| this.bkgdSsoSilent(result, "acquireTokenPopup"); | ||
|
|
||
| return result; | ||
| }) | ||
| .catch((e: Error) => { | ||
|
|
@@ -984,6 +991,78 @@ export class StandardController implements IController { | |
| visibilityChangeCount: 1, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Fire-and-forget ssoSilent call to refresh tokens in the background. | ||
| * This method does not block the caller and tracks telemetry for success/failure. | ||
| * This method only executes if enableBackgroundSSO is set to true in the cache configuration. | ||
| * @param result - The authentication result from the parent operation | ||
| * @param parentApiId - The API ID of the parent operation for logging purposes | ||
| */ | ||
| private bkgdSsoSilent( | ||
| result: AuthenticationResult, | ||
| parentApiId: string | ||
| ): void { | ||
| // Check if background SSO is enabled | ||
| if (!this.config.auth.enableBackgroundSSO) { | ||
| return; | ||
| } | ||
|
|
||
| const correlationId = createNewGuid(); | ||
| const bgSsoSilentMeasurement = this.performanceClient.startMeasurement( | ||
| PerformanceEvents.BackgroundSsoSilent, | ||
| correlationId | ||
| ); | ||
| bgSsoSilentMeasurement.add({ | ||
| parentApiId: parentApiId, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're calling this ApiId we should use |
||
| }); | ||
|
|
||
| this.logger.verbose( | ||
| `Background ssoSilent initiated after ${parentApiId}`, | ||
| correlationId | ||
| ); | ||
|
|
||
| /* | ||
| * Use setTimeout to ensure this runs in a separate macrotask after the current call stack completes | ||
| * This ensures the result is returned to the caller before ssoSilent starts and doesn't affect performance | ||
| */ | ||
| setTimeout(() => { | ||
| const ssoSilentRequest: SsoSilentRequest = { | ||
| account: result.account, | ||
| correlationId: correlationId, | ||
| }; | ||
|
|
||
| this.ssoSilent(ssoSilentRequest) | ||
| .then((ssoResult) => { | ||
| this.logger.verbose( | ||
| `Background ssoSilent completed successfully after ${parentApiId}`, | ||
| correlationId | ||
| ); | ||
| bgSsoSilentMeasurement.end( | ||
| { | ||
| success: true, | ||
| accessTokenSize: ssoResult.accessToken.length, | ||
| idTokenSize: ssoResult.idToken.length, | ||
| }, | ||
| undefined, | ||
| ssoResult.account | ||
| ); | ||
| }) | ||
| .catch((error: Error) => { | ||
| this.logger.warning( | ||
| `Background ssoSilent failed after ${parentApiId}: ${error.message}`, | ||
| correlationId | ||
| ); | ||
| bgSsoSilentMeasurement.end( | ||
| { | ||
| success: false, | ||
| }, | ||
| error, | ||
| result.account | ||
| ); | ||
| }); | ||
| }, 0); | ||
| } | ||
| // #endregion | ||
|
|
||
| // #region Silent Flow | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.