Reputation: 240
I'm working on a .NET 8 Blazor project and I'm trying to implement Azure AD B2C authentication. According to Microsoft's documentation, I'm using RemoteAuthenticatorView
. It works fine in WebAssembly mode, but I'm encountering issues when using "Interactive Auto".
When I use "Interactive Auto", I get the following error:
Cannot provide a value for property ‘AuthenticationService’ on type ‘Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorView’. There is no registered service of type ‘Microsoft.AspNetCore.Components.WebAssembly.Authentication.IRemoteAuthenticationService`1[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState]’
In an attempt to resolve this, I added builder.Services.AddApiAuthorization();
to my code. However, this resulted in another error:
Unable to cast object of type ‘Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider’ to type ‘Microsoft.AspNetCore.Components.WebAssembly.Authentication.IRemoteAuthenticationService`1[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState]’
I'm looking for guidance on how to resolve these errors and successfully implement Azure AD B2C authentication in my Blazor project. Any help would be greatly appreciated.
Upvotes: 1
Views: 374
Reputation: 1
The error message suggests there might be an issue with the AuthenticationStateProvider being used. Make sure you are using the correct provider for Blazor WebAssembly. It should be RemoteAuthenticationStateProvider.
builder.Services.AddScoped<AuthenticationStateProvider, RemoteAuthenticationStateProvider>();
Upvotes: -1