gpt4 book ai didi

Azure AD 注销

转载 作者:行者123 更新时间:2023-12-01 12:22:51 27 4
gpt4 key购买 nike

我喜欢从 Azure 广告 B2C 中注销我的 Web 应用程序。我尝试了以下示例 https://www.janaks.com.np/azure-ad-identity-provider-in-aspnet-core-application/ 中建议的操作。

if (HttpContext.User.Identity.IsAuthenticated)
{
await HttpContext.Authentication.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}

在 Startup.cs 中进行以下配置:

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = settings.SignInPolicyId,
AutomaticChallenge = true,
CallbackPath = settings.SignInCallbackPath,
ClientId = settings.ClientId,
MetadataAddress = string.Format(settings.AadInstance, settings.Tenant, settings.SignInPolicyId),
PostLogoutRedirectUri = settings.RedirectUri,
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name"
},
AutomaticAuthenticate = true,
Scope = { "openid" },
ResponseType = "id_token",
GetClaimsFromUserInfoEndpoint = true
});

但是当我尝试从 web 应用程序注销时,将抛出以下异常:

InvalidOperationException: No authentication handler is configured to handle the scheme: OpenIdConnect

感谢您的帮助。

最佳答案

您必须识别您设置的身份验证方案:

if (HttpContext.User.Identity.IsAuthenticated)
{
await HttpContext.Authentication.SignOutAsync(settings.SignInPolicyId);
await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}

您必须以某种方式获取此 Controller 的策略 ID,并使用它来识别适当的中间件。

关于Azure AD 注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42504397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com