Blazor Server App Failed to complete negotiation with the server: error

Viewed 20

I build a blazor server application that supports Azure AD login and Azure B2C login. This works fine and I can decide what is displayed to the user using the authentication scheme.

If I login with Azure AD everything works fine. If I login with Azure B2C events (like onclick) are not raised.

After starting the application the user is sent to a login page. On this page he can decide to login with AD or B2C.

On this page I get the following error:

[2022-09-07T12:09:46.429Z] Error: Failed to start the connection: Error
[2022-09-07T12:09:46.430Z] Error: Error
Error: Cannot send data if the connection is not in the 'Connected' State.
    at e.send (https://localhost:5001/_framework/blazor.server.js:1:51662)
    at e.sendMessage (https://localhost:5001/_framework/blazor.server.js:1:22519)
    at e.sendWithProtocol (https://localhost:5001/_framework/blazor.server.js:1:22581)
    at https://localhost:5001/_framework/blazor.server.js:1:23244
    at new Promise (<anonymous>)
    at e.invoke (https://localhost:5001/_framework/blazor.server.js:1:23041)
    at e.<anonymous> (https://localhost:5001/_framework/blazor.server.js:21:27207)
    at https://localhost:5001/_framework/blazor.server.js:21:26507
    at Object.next (https://localhost:5001/_framework/blazor.server.js:21:26612)
    at https://localhost:5001/_framework/blazor.server.js:21:25524

After login with AD, the error is cleared and everything works fine. If I log in with B2C this error still occurs and it seems that the application is not longer connected to the server.

I think this is the reason why the application does fire events.

1 Answers

I was able to fix the problem.

Needed add the following:

endpoints.MapRazorPages().RequireAuthorization(
    new AuthorizeAttribute
    {
        AuthenticationSchemes = $"{OpenIdConnectDefaults.AuthenticationScheme},{FischerLib.Extensions.Constants.B2CAuthenticationScheme}"
    }
);

endpoints.MapBlazorHub().RequireAuthorization(
    new AuthorizeAttribute
    {
        AuthenticationSchemes = $"{OpenIdConnectDefaults.AuthenticationScheme},{FischerLib.Extensions.Constants.B2CAuthenticationScheme}"
    }
);
Related