要解决Blazor WebAssembly AuthenticationService.js在某些重定向时未调用openid-configuration的问题,你可以尝试以下解决方法:
元素中添加下面的代码来引用这些依赖项:
确保将Version
替换为你想要使用的版本号。
Program.cs
文件中正确配置了AuthenticationService
。验证你的代码与下面的示例是否一致:builder.Services.AddHttpClient("YourServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler();
builder.Services.AddScoped(sp => sp.GetRequiredService().CreateClient("YourServerAPI"));
builder.Services.AddApiAuthorization();
await builder.Build().RunAsync();
确保将YourServerAPI
替换为你的API服务的名称。
openid-configuration
终结点。在你的Blazor组件的代码中,找到使用AuthenticationService
的地方,并添加以下代码:protected override async Task OnInitializedAsync()
{
// 从服务端获取OpenID配置信息
var openidConfiguration = await Http.GetFromJsonAsync("your-openid-configuration-url");
// 在AuthenticationService中设置OpenID配置
var authService = (IAccessTokenProvider)AuthenticationService;
await authService.SetConfigurationAsync(openidConfiguration);
await base.OnInitializedAsync();
}
确保将your-openid-configuration-url
替换为你实际的OpenID配置终结点。
这些解决方法应该能够帮助你解决Blazor WebAssembly AuthenticationService.js未调用openid-configuration的问题。