Repository navigation
Fix MSAL initialization - #69726
Fix MSAL initialization#69726
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Required frozen review evidence was unavailable, leaving implementation and regression coverage insufficiently validated for approval.
0 open findings
What changed in this PR
Addresses the reported MSAL initialization race affecting Blazor WebAssembly authentication after refresh.
Changes:
- Shares one initialization promise across concurrent callers and allows retries after failure.
- Adds unit coverage for sequential, overlapping, and failed initialization.
- Adds browser coverage for concurrent initialization and page refresh.
| File | Description |
|---|---|
| src/Components/WebAssembly/Authentication.Msal/test/AuthenticationService.test.ts | Tests initialization ordering, reuse, and retries. |
| src/Components/WebAssembly/Authentication.Msal/src/Interop/AuthenticationService.ts | Shares initialization and retains the matching client. |
| src/Components/Web.JS/jest.config.js | Includes the MSAL unit tests. |
| src/Components/test/testassets/Components.WasmRemoteAuthentication/Components.WasmRemoteAuthentication.csproj | References MSAL for browser testing. |
| src/Components/test/testassets/Components.TestServer/wwwroot/msal-initialization.html | Adds a concurrent-initialization browser test page. |
| src/Components/test/E2ETest/Tests/RemoteAuthenticationTest.cs | Checks initialization before and after refresh. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
✅ No documentation PR was created. Confidence that documentation is needed: 5% No docs needed: bug fix restoring intended MSAL initialization behavior, with tests only otherwise. Documentation surfaces considered
|
We regressed MSAL initialization in #66055.
In that PR, we added
await AuthenticationService.instance.initialize();beforeinitializeMsalHandlercall.That means, two calls to
initcould overlap in a way that's not safe.AuthenticationService._initializedis false, we enter theif.MsalAuthorizeServiceand assign toinstance.await initialize(), subsequent lines are waiting for this promise to complete.AuthenticationService._initializedis false, we enter theif.MsalAuthorizeServiceand assign toinstance(the same static field).await initialize()(on the second instance).AuthenticationService.instance.initializeMsalHandler, but now that is the second instance that's not yet initialized.Fixes (hopefully) #68549 - intentionally not closing that issue until we are confident about the fix and backport it to 10.0.x.