在.NET 8 Blazor项目中实现Azure AD B2C身份验证(渲染模式:InteractiveAuto)

问题描述 投票:0回答:1

我正在开发 .NET 8 Blazor 项目,并尝试实现 Azure AD B2C 身份验证。根据微软的文档,我使用的是

RemoteAuthenticatorView
。它在 WebAssembly 模式下工作正常,但我在使用“Interactive Auto”时遇到问题。

当我使用“交互式自动”时,出现以下错误:

无法为类型“Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorView”上的属性“AuthenticationService”提供值。没有类型为“Microsoft.AspNetCore.Components.WebAssembly.Authentication.IRemoteAuthenticationService`1[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState]”的已注册服务

为了解决此问题,我在代码中添加了

builder.Services.AddApiAuthorization();
。然而,这导致了另一个错误:

无法将“Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider”类型的对象转换为“Microsoft.AspNetCore.Components.WebAssembly.Authentication.IRemoteAuthenticationService`1[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState]”

我正在寻找有关如何解决这些错误并在我的 Blazor 项目中成功实施 Azure AD B2C 身份验证的指南。任何帮助将不胜感激。

c# asp.net .net blazor azure-ad-b2c
1个回答
0
投票

错误消息表明正在使用的 AuthenticationStateProvider 可能存在问题。确保您使用正确的 Blazor WebAssembly 提供程序。应该是RemoteAuthenticationStateProvider。

builder.Services.AddScoped<AuthenticationStateProvider, RemoteAuthenticationStateProvider>();
© www.soinside.com 2019 - 2024. All rights reserved.