Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Since Microsoft.Authentication.WebAssembly.Msal 10.0.8, a successful redirect login can send the user to the app root (Navigation.BaseUri) instead of the page they asked for.
This regressed in #66094, which added an await to AuthenticationService.init before _initialized is set:
public static async init(settings: AuthorizeServiceConfiguration, jsLoggingOptions: JavaScriptLoggingOptions) {
if (!AuthenticationService._initialized) {
AuthenticationService.instance = new MsalAuthorizeService(settings, new Logger(jsLoggingOptions));
await AuthenticationService.instance.initialize(); // <-- added in #66094
AuthenticationService.instance.initializeMsalHandler();
AuthenticationService._initialized = true;
}
}Before 10.0.8 this method ran synchronously (despite being marked async), so it couldn't be re-entered. Now, if two .NET callers reach RemoteAuthenticationService.EnsureAuthService() at the same time, both pass the _initialized check. Each one creates its own MsalAuthorizeService and PublicClientApplication, and each calls initializeMsalHandler(), which runs handleRedirectPromise().
A common way to get two concurrent callers on startup:
AuthorizeRouteView/CascadingAuthenticationStateresolving the auth state (getUser)- a component in the layout (for example a nav menu) making an API call through
BaseAddressAuthorizationMessageHandler(getAccessToken)
On the login-callback page, both instances run handleResult(result):
- The first instance calls
retrieveState(null, result.state). That finds the saved{ returnUrl }in sessionStorage and removes it. - The second instance gets a result too, but its
retrieveStatefinds nothing, so it returnssuccess(undefined). - The second instance is the one left in
AuthenticationService.instance, socompleteSignIn()returns{ status: "success" }with nostate. RemoteAuthenticatorViewCore.ProcessLogInCallbackcallsGetReturnUrl(null). There's no history entry state after the full-page redirect, so it falls back toNavigation.BaseUri.
Trace from instrumenting sessionStorage and history (URLs shortened):
/some/page | pushState /authentication/login {"returnUrl":"https://app/some/page",...}
/authentication/login | sessionStorage.set ...AuthorizeService.<id> = {"returnUrl":"https://app/some/page"}
/authentication/login-callback | sessionStorage.get ...AuthorizeService.<id> -> {"returnUrl":"https://app/some/page"}
/authentication/login-callback | sessionStorage.remove ...AuthorizeService.<id> (retrieveState < handleResult < completeAuthentication)
/authentication/login-callback | sessionStorage.get ...AuthorizeService.<id> -> null <-- second instance
/authentication/login-callback | replaceState https://app/ {"userState":null}
After the redirect, await AuthenticationService.instance._redirectCallback gives {"status":"success"} with no state property.
Expected Behavior
After signing in, the user goes back to the ReturnUrl passed to NavigateToLogin, as in 10.0.7 and earlier. AuthenticationService.init should be safe to call concurrently. For example, cache the init promise:
private static _initPromise: Promise<void> | undefined;
public static init(settings: AuthorizeServiceConfiguration, jsLoggingOptions: JavaScriptLoggingOptions) {
return AuthenticationService._initPromise ??= (async () => {
const instance = new MsalAuthorizeService(settings, new Logger(jsLoggingOptions));
await instance.initialize();
instance.initializeMsalHandler();
AuthenticationService.instance = instance;
AuthenticationService._initialized = true;
})();
}The .NET side could also serialise EnsureAuthService() (for example with a cached Task), so it doesn't call init more than once.
Steps To Reproduce
- Create a Blazor WebAssembly app with
AddMsalAuthentication(Entra ID). UseLoginMode = "redirect"and the standardRedirectToLogincomponent, which callsNavigation.NavigateToLogin(...). - In
MainLayout(rendered while auth is still resolving), add a component that calls the API onOnInitializedAsyncthrough anHttpClientthat usesBaseAddressAuthorizationMessageHandler. CatchAccessTokenNotAvailableException. - Put an
[Authorize]page at/protected. - While signed out, browse straight to
/protectedand complete the Microsoft sign-in. - Actual: you land on
/. Expected: you land on/protected.
Remove the layout component's startup API call and the return URL works again.
Workaround
In Program.cs, resolve the auth state once before RunAsync(), so the JS service is fully initialised before anything can race into it:
var host = builder.Build();
await using (var scope = host.Services.CreateAsyncScope())
await scope.ServiceProvider.GetRequiredService<AuthenticationStateProvider>().GetAuthenticationStateAsync();
await host.RunAsync();Exceptions (if any)
None. The navigation just goes to the wrong place.
.NET Version
10.0.12 (regression introduced in 10.0.8; 10.0.7 not affected). The bundled @azure/msal-browser is 4.30.0.
Anything else?
- I compared
AuthenticationService.jsin the NuGet packages: 10.0.7 has the synchronousinit, and 10.0.8 through 10.0.12 have theawait. - Browser: Chrome. Hosted Blazor WASM (ASP.NET Core host,
MapFallbackToFile("index.html")). mainmay have the sameinitshape. Worth checking whether the fix needs to go there as well asrelease/10.0.
Activity
MihuBot commentedon Oct 9, 2026
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):
github-actions commentedon Oct 9, 2026
Triage Summary
Area:
area-auth(MSAL login/redirect handling inMicrosoft.Authentication.WebAssembly.Msal)Type:
Bug(login return URL is dropped after redirect sign-in)Regression Info
Navigation.BaseUriinstead of the requestedReturnUrl. The reporter comparedAuthenticationService.jsacross packages and attributes the change to theawaitadded inAuthenticationService.initby [release/10.0] Update azure/msal-browser #66094.Potential Duplicates
Notes
droyad commentedon Oct 9, 2026
Closing as a duplicate of #68136. I've moved the root cause, trace and workaround there, and linked the fixes: #69735 and #69736.