Repository navigation
Conversation
init awaits msal.js initialize() before setting _initialized, so a second call arriving during that await creates another MsalAuthorizeService. Both instances process the redirect response: the first consumes the saved state (including the return URL), and the second, which becomes AuthenticationService.instance, completes sign-in without state, so the user is sent to the base URI. Cache the initialization promise instead, as the OIDC AuthenticationService already does, so concurrent callers await the same initialization. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks for your PR, @droyad. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The browser navigation regression lacks the required permanent Selenium coverage.
1 open finding
What changed in this PR
Caches MSAL initialization so concurrent callers share one promise and avoid duplicate redirect handling.
Changes:
- Replaces the initialization flag with a cached promise.
- Extracts initialization into
initializeCore.
| File | Description |
|---|---|
AuthenticationService.ts |
Deduplicates concurrent MSAL initialization. |
🧠 Review effort: Balanced
| await AuthenticationService.instance.initialize(); | ||
| AuthenticationService.instance.initializeMsalHandler(); | ||
| AuthenticationService._initialized = true; | ||
| AuthenticationService._initialized = AuthenticationService.initializeCore(settings, jsLoggingOptions); |
Author
There was a problem hiding this comment.
There is no existing MSAL testing
This was referenced Oct 9, 2026
Closed
Member
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Make MSAL AuthenticationService.init safe to call concurrently
Cache the MSAL interop's init promise so concurrent calls don't race
Description
#66055 (backported to 10.0 in #66094) added
await AuthenticationService.instance.initialize()to the MSALAuthenticationService.init, but_initializedis still only set after that await. Before that change the method body ran synchronously, so it couldn't be re-entered. Now, anyinitcall that arrives while msal.js is initialising passes the check and creates a secondMsalAuthorizeService.On a login callback, both instances run
handleRedirectPromise()andhandleResult():AuthenticationService.instanceand returnssuccesswith no state.RemoteAuthenticatorViewCorethen falls back toNavigation.BaseUri, so the user lands on the app root instead of the page they asked for.On the .NET side,
RemoteAuthenticationService.EnsureAuthService()doesn't serialise its calls intoinit, so two concurrent startup callers are enough to trigger this. A common pair is the authentication state lookup and an access token request fromBaseAddressAuthorizationMessageHandlerin a layout component.This change caches the initialisation promise, matching what the OIDC
AuthenticationServiceinWebAssembly.Authenticationalready does ("Multiple initializations can start concurrently and we want to avoid that"). Concurrent callers now await the same initialisation.A companion PR, #69736, makes
EnsureAuthService()share a single init call on the .NET side as well. Either change fixes the bug; together, neither layer depends on the other to dedupe.Testing
There's no JS test project for this interop, so I checked it with a throwaway harness:
AuthenticationService.tswith esbuild against a stub@azure/msal-browserwhoseinitialize()resolves after 20ms.inittwice concurrently, then once more.handleRedirectPromisecallsmainThe change type-checks under the repo's
Shared.JStsconfig (strict) with@azure/msal-browser@4.30.0. I also reproduced the original bug end to end in a real app on 10.0.12 by instrumenting sessionStorage across the redirect; the trace is in this comment on #68136.Fixes #68136
🤖 Generated with Claude Code