- 确保Identity Server的配置正确,并且.well-known/openid-configuration在Identity Server的配置文件中被正确地指定。
- 在Blazor WASM应用程序的Startup.cs文件中,确保已正确配置添加IdentityServer:
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookie")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:5001"; // replace with the Url of your Identity Provider
options.ClientId = "blazorwasm";
options.ResponseType = "code";
options.UsePkce = true;
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.SaveTokens = true;
});
- 确认Blazor WASM前端应用程序包含@using Microsoft.AspNetCore.Components.WebAssembly.Authentication和元素:
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal
// … other content …
- 重启Blazor WASM应用程序,并尝试进行身份验证,以确保.well-known/openid-configuration被正确地加载。