-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement redirect bridge to support COOP #8118
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
konstantin-msft
wants to merge
67
commits into
msal-v5
Choose a base branch
from
popup_coop_support
base: msal-v5
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.
+4,664
−1,358
Open
Changes from 32 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
0e9e1c4
- Update popup client with a minimal functionality to handle popup CO…
konstantin-msft 8da953b
- Update popup client with a minimal functionality to handle popup CO…
konstantin-msft 9759da1
- Update popup client with a minimal functionality to handle popup CO…
konstantin-msft b785cbb
- Code size optimizations
konstantin-msft 125588f
- Code optimizations
konstantin-msft 7eb65d7
- Refactor silent client to use redirect bridge for both popup and SS…
konstantin-msft 1be20ef
- Refactor silent client to use redirect bridge for both popup and SS…
konstantin-msft d72ba13
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft 2b46d6a
Update package-lock.json
konstantin-msft da8168d
- Update unit tests.
konstantin-msft f186235
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft afae280
Fix post-merge errors.
konstantin-msft e7e5c54
Change files
konstantin-msft 40b8e3e
Add redirectBridgeEmptyResponse error code and update waitForBridgeRe…
konstantin-msft 2a28584
- Update redirect page for samples
konstantin-msft afe6890
- Remove redundant "unloadWindow" listener
konstantin-msft 240757c
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft c3a5ed9
Merge branch 'msal-v5' of https://github.com/AzureAD/microsoft-authen…
lalimasharda a4c9ce5
Merge branch 'popup_coop_support' of https://github.com/AzureAD/micro…
lalimasharda 8a167fc
Merge branch 'msal-v5' of https://github.com/AzureAD/microsoft-authen…
lalimasharda 49b3506
- Add navigation to broadcastResponseToMainFrame
konstantin-msft 2895e20
- Add error description.
konstantin-msft 076df1d
- Resolve dep cycle
konstantin-msft 5cb8ca8
- Add support for overriding ongoing interactions in popup flows
konstantin-msft bb9480a
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft 6636748
- Update core e2e tests
konstantin-msft 48e01bf
- Address review comments
konstantin-msft b42be72
- Update COOP migration guide
konstantin-msft 15086a0
- Update error doc
konstantin-msft 2780349
- Handle hybrid URL response format
konstantin-msft 4c1a103
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft def925e
- Update migration doc
konstantin-msft 704968f
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft 5ffe984
Update docs/errors.md
konstantin-msft ba93bd2
Update lib/msal-browser/docs/v4-migration.md
konstantin-msft f786341
Update lib/msal-browser/docs/v4-migration.md
konstantin-msft 7d7bdd3
Update lib/msal-browser/docs/v4-migration.md
konstantin-msft 0aadd91
Update lib/msal-browser/docs/v4-migration.md
konstantin-msft 4c73bbd
Update lib/msal-browser/docs/v4-migration.md
konstantin-msft 18b1e4f
- Pick up clientId from the session storage interaction key instead o…
konstantin-msft 348c75e
- Formatting
konstantin-msft d45e1d4
- Use `AuthError` to throw in the redirect bridge
konstantin-msft 2644d40
- Update API doc
konstantin-msft 25996a0
- Update e2e tests
konstantin-msft 48ba45d
Merge branch 'msal-v5' of https://github.com/AzureAD/microsoft-authen…
lalimasharda b58bd67
Merge branch 'popup_coop_support' of https://github.com/AzureAD/micro…
lalimasharda 9a7bd3d
- Update e2e tests
konstantin-msft ece3225
Merge remote-tracking branch 'origin/popup_coop_support' into popup_c…
konstantin-msft 9c32ec0
- Add visual examples on how to handle interaction override flag.
konstantin-msft a5572f0
- Update API doc
konstantin-msft cfef9f8
- Update redirect URI switch for express sample.
konstantin-msft be545c8
- Address review comments
konstantin-msft f5b340c
- Update API doc
konstantin-msft 7c088ed
- Increase version switch timeout for express sample
konstantin-msft 22be0a0
- Update redirect URI documentation
konstantin-msft ce57d1c
Update docs/errors.md
konstantin-msft 53d9d6b
popup coop e2e tests (#8165)
lalimasharda 8d09b33
Update lib/msal-browser/src/utils/BrowserUtils.ts
konstantin-msft 38566ec
Update lib/msal-browser/src/utils/BrowserUtils.ts
konstantin-msft 2c8fc69
Update lib/msal-browser/src/utils/BrowserUtils.ts
konstantin-msft 35b7d56
Update lib/msal-browser/docs/login-user.md
konstantin-msft 98116eb
Update lib/msal-browser/docs/login-user.md
konstantin-msft 3be38b9
Update lib/msal-browser/docs/login-user.md
konstantin-msft 3c69a41
Update lib/msal-browser/docs/login-user.md
konstantin-msft 5237f78
Update lib/msal-browser/docs/login-user.md
konstantin-msft ace9170
Merge branch 'msal-v5' into popup_coop_support
konstantin-msft 569e764
Refactor error handling in BrowserUtils and update error documentation
konstantin-msft 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-3b6b0844-0608-4d31-bba7-7c7177ad52f1.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": "minor", | ||
| "comment": "Implement redirect bridge to support COOP [#8118](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8118)", | ||
| "packageName": "@azure/msal-browser", | ||
| "email": "kshabelko@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-common-cde5a6b6-5532-4445-945e-4ca192b96714.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": "minor", | ||
| "comment": "Implement redirect bridge to support COOP [#8118](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8118)", | ||
| "packageName": "@azure/msal-common", | ||
| "email": "kshabelko@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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,7 +263,7 @@ This error occurs when MSAL.js surpasses the allotted storage limit when attempt | |
| - Authority mismatch error. Authority provided in login request or PublicClientApplication config does not match the environment of the provided account. Please use a matching account or make an interactive request to login to this authority. | ||
|
|
||
| ### `invalid_request_method_for_EAR` | ||
| - The EAR protocol cannot be used with HTTP method `GET`. The `httpMethod` parameter in all requests using `protocolMode: ProtocolMode.EAR` must be either unset or `"POST"`/`HttpMethod.POST`. | ||
| - The EAR protocol cannot be used with HTTP method `GET`. The `httpMethod` parameter in all requests using `protocolMode: ProtocolMode.EAR` must be either unset or `"POST"`/`HttpMethod.POST`. | ||
|
|
||
| ## Interaction required errors | ||
|
|
||
|
|
@@ -558,6 +558,40 @@ If you are unable to figure out why this error is being thrown please [open an i | |
| - Refresh the page. Does the error go away? | ||
| - Open your application in a new tab. Does the error go away? | ||
|
|
||
| ### `interaction_in_progress_cancelled` | ||
|
|
||
| - The current interaction was cancelled by a new interaction request with `overrideInteractionInProgress` set to `true`. | ||
|
|
||
| This error is thrown when an existing popup interaction is cancelled because a new popup request was initiated with the `overrideInteractionInProgress` flag set to `true`. This is not necessarily an error condition - it indicates that the previous interaction was intentionally cancelled to allow a new one to proceed. | ||
|
|
||
| **When This Occurs:** | ||
|
|
||
| This error is thrown for the **previous/cancelled** interaction when: | ||
| 1. A popup interaction is in progress (e.g., `acquireTokenPopup`) | ||
| 2. A new popup request is made with `overrideInteractionInProgress: true` | ||
| 3. The library cancels the pending interaction and starts the new one | ||
|
|
||
| **Example:** | ||
|
|
||
| ```javascript | ||
| // First popup request starts | ||
| const request1 = { scopes: ["User.Read"] }; | ||
| const promise1 = msalInstance.acquireTokenPopup(request1); | ||
|
|
||
| // User closes the popup or something goes wrong | ||
| // App decides to retry with override flag | ||
| const request2 = { | ||
| scopes: ["User.Read"], | ||
| overrideInteractionInProgress: true // Override the previous interaction | ||
| }; | ||
| const promise2 = msalInstance.acquireTokenPopup(request2); | ||
|
|
||
| // promise1 will reject with interaction_in_progress_cancelled | ||
| // promise2 will proceed normally | ||
| ``` | ||
|
|
||
| **Note:** This error should only be seen when you explicitly use the `overrideInteractionInProgress` flag. Under normal circumstances, concurrent interaction attempts will throw `interaction_in_progress` instead. | ||
|
|
||
| ### `popup_window_error` | ||
|
|
||
| - Error opening popup window. This can happen if you are using IE or if popups are blocked in the browser. | ||
|
|
@@ -570,43 +604,61 @@ If you are unable to figure out why this error is being thrown please [open an i | |
|
|
||
| - User cancelled the flow. | ||
|
|
||
| ### `monitor_popup_timeout` | ||
| ### `redirect_bridge_timeout` | ||
|
|
||
| - Token acquisition in popup failed due to timeout. | ||
| - Communication with the redirect page (popup or iframe) timed out while waiting for authentication response. | ||
|
|
||
| ### `monitor_window_timeout` | ||
| **Error Messages**: | ||
|
|
||
| - Token acquisition in iframe failed due to timeout. | ||
| - Token acquisition in popup failed due to timeout. | ||
| - Token acquisition in iframe failed due to timeout. | ||
|
|
||
| **Error Messages**: | ||
| This error can be thrown when calling `ssoSilent`, `acquireTokenSilent`, `acquireTokenPopup` or `loginPopup` when the redirect bridge script fails to send the authentication response back to the main window within the configured timeout period. | ||
|
|
||
| - Token acquisition in iframe failed due to timeout. | ||
| **What is the redirect bridge?** | ||
|
|
||
| This error can be thrown when calling `ssoSilent`, `acquireTokenSilent`, `acquireTokenPopup` or `loginPopup` and there are several reasons this could happen. These are a few of the most common: | ||
| The redirect bridge is a mechanism that enables authentication flows in COOP (Cross-Origin-Opener-Policy) enabled applications. When COOP headers are present, popup and iframe windows cannot directly communicate with the main application window. The redirect bridge solves this by using the BroadcastChannel API to transmit authentication responses from the redirect page back to the main window. For more details on COOP support and the redirect bridge, see the [COOP Migration Guide](../lib/msal-browser/docs/v4-migration.md#cross-origin-opener-policy-coop-support). | ||
|
|
||
| 1. The page you use as your `redirectUri` is removing or manipulating the hash | ||
| 1. The page you use as your `redirectUri` is automatically navigating to a different page | ||
| 1. You are being throttled by your identity provider. The identity provider may throttle clients that make too many similar requests in a short period of time. Never implement an endless retry mechanism or retry more than once. Attempts to retry non-network errors typically yield the same result. See [throttling guide](#Throttling) for more details. | ||
| 1. Your identity provider did not redirect back to your `redirectUri`. | ||
| **Common Causes:** | ||
|
|
||
| **Important**: If your application uses a router library (e.g. React Router, Angular Router), please make sure it does not strip the hash or auto-redirect while MSAL token acquisition is in progress. If possible, it is best if your `redirectUri` page does not invoke the router at all. | ||
| This timeout typically occurs for the following reasons: | ||
|
|
||
| #### Issues caused by the redirectUri page | ||
| 1. The page you use as your `redirectUri` is not loading the `msal-redirect-bridge.js` script | ||
| 1. The redirect page is removing or manipulating the hash before the bridge script can process it | ||
| 1. The redirect page is automatically navigating to a different page before the bridge can communicate the response | ||
| 1. Your identity provider is being slow to redirect back to your `redirectUri` (network latency) | ||
| 1. You are being throttled by your identity provider due to too many requests in a short period | ||
|
|
||
| When you make a silent call, in some cases, an iframe will be opened and will navigate to your identity provider's authorization page. After the identity provider has authorized the user it will redirect the iframe back to the `redirectUri` with the authorization code or error information in the hash fragment. The MSAL instance running in the frame or window that originally made the request will extract this response hash and process it. If your `redirectUri` is removing or manipulating this hash or navigating to a different page before MSAL has extracted it you will receive this timeout error. | ||
| **Resolution Steps:** | ||
|
|
||
| ✔️ To solve this problem you should ensure that the page you use as your `redirectUri` is not doing any of these things, at the very least, when loaded in a popup or iframe. We recommend using a blank page as your `redirectUri` for silent and popup flows to ensure none of these things can occur. | ||
| ✔️ **Ensure the redirect bridge script is loaded:** | ||
|
|
||
| You can do this on a per request basis, for example: | ||
| Your `redirectUri` page must include the redirect bridge script to enable communication back to the main window: | ||
|
|
||
| ```javascript | ||
| msalInstance.acquireTokenSilent({ | ||
| scopes: ["User.Read"], | ||
| redirectUri: "http://localhost:3000/blank.html", | ||
| }); | ||
| ```html | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Redirect</title> | ||
| </head> | ||
| <body> | ||
| <script src="path/to/msal-redirect-bridge.js"></script> | ||
| <script> | ||
| msalRedirectBridge.sendRedirectPayloadToMainFrame(); | ||
| </script> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| Remember that you will need to register this new `redirectUri` on your App Registration. | ||
| **Important**: If your application uses a router library (e.g. React Router, Angular Router), please make sure it does not strip the hash or auto-redirect while MSAL token acquisition is in progress. If possible, it is best if your `redirectUri` page does not invoke the router at all. | ||
|
|
||
| #### Issues caused by the redirectUri page | ||
|
|
||
| When you make a silent call, in some cases, an iframe will be opened and will navigate to your identity provider's authorization page. After the identity provider has authorized the user it will redirect the iframe back to the `redirectUri` with the authorization code or error information in the hash fragment. The MSAL redirect bridge running in the iframe will broadcast response to MSAL instance running in the frame or window that originally made the request. If your `redirectUri` is removing or manipulating this hash or navigating to a different page before MSAL redirect bridge has extracted it you will receive this timeout error. | ||
|
|
||
| ✔️ To solve this problem you should ensure that the page you use as your `redirectUri` is not doing any of these things, at the very least, when loaded in a popup or iframe. | ||
|
||
|
|
||
| Remember that you will need to register `redirectUri` on your App Registration. | ||
|
|
||
| **Notes regarding Angular and React:** | ||
|
|
||
|
|
@@ -641,24 +693,27 @@ Some B2C flows are expected to throw this error due to their need for user inter | |
|
|
||
| Another potential reason the identity provider may not redirect back to your application in time may be that there is some extra network latency. | ||
|
|
||
| ✔️ The default timeout is about 10 seconds and should be sufficient in most cases, however, if your identity provider is taking longer than that to redirect you can increase this timeout in the MSAL config with either the `iframeHashTimeout`, `windowHashTimeout` or `loadFrameTimeout` configuration parameters. | ||
| ✔️ The default timeout is about 10 seconds and should be sufficient in most cases, however, if your identity provider is taking longer than that to redirect you can increase this timeout in the MSAL config with either the `iframeBridgeTimeout` or `popupBridgeTimeout` configuration parameters. | ||
konstantin-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```javascript | ||
| const msalConfig = { | ||
| auth: { | ||
| clientId: "your-client-id", | ||
| }, | ||
| system: { | ||
| windowHashTimeout: 9000, // Applies just to popup calls - In milliseconds | ||
| iframeHashTimeout: 9000, // Applies just to silent calls - In milliseconds | ||
| loadFrameTimeout: 9000, // Applies to both silent and popup calls - In milliseconds | ||
| popupBridgeTimeout: 50000, // Applies just to popup calls - In milliseconds | ||
| iframeBridgeTimeout: 9000, // Applies just to silent calls - In milliseconds | ||
tnorling marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
| > Please consult the [Troubleshooting Single-Sign On](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/FAQ.md#troubleshooting-single-sign-on) section of the MSAL Browser FAQ if you are having trouble with the `ssoSilent` API. | ||
|
|
||
| ### `redirect_bridge_empty_response` | ||
|
|
||
| - The redirect bridge returned an empty response, indicating the redirect bridge script may have been modified or replaced. | ||
|
|
||
| ### `redirect_in_iframe` | ||
|
|
||
| - Redirects are not supported for iframed or brokered applications. Please ensure you are using MSAL.js in a top frame of the window if using the redirect APIs, or use the popup APIs. | ||
|
|
||
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.
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.
Nit: A visual probably will make it easy. Not a blocking comment.
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.
Added visuals to express and react-router samples. Links are located in
login-user.md