该问题可能由于未正确配置身份服务器和 Blazor 应用程序之间的身份验证流程而导致。 可以尝试以下步骤进行解决:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.Authority = "{your_identity_server_url}";
options.ClientId = "{your_client_id}";
options.ClientSecret = "{your_client_secret}";
options.ResponseType = "code";
options.Scope.Add("openid");
options.Scope.Add("profile");
});
Authenticated
Not Authenticated
new Client
{
ClientId = "{your_client_id}",
ClientSecrets = { new Secret("{your_client_secret}".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
RedirectUris = { "https://localhost:5001/login-callback" },
FrontChannelLogoutUri = "https://localhost:5001/signout-oidc",
PostLogoutRedirectUris = { "https://localhost:5001/" },
AllowOfflineAccess = true,
AllowedScopes = { "