Azure广告注销
我喜欢从azure广告b2c注销我的Web应用程序。我尝试了以下示例中建议的方法 在Startup.cs中使用以下配置:Azure广告注销,azure,logout,azure-ad-b2c,Azure,Logout,Azure Ad B2c,我喜欢从azure广告b2c注销我的Web应用程序。我尝试了以下示例中建议的方法 在Startup.cs中使用以下配置: app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { AuthenticationScheme = settings.SignInPolicyId, AutomaticChallenge = true, CallbackPath = settings.SignInCallbackPa
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
});
但当我尝试从webapp注销时,将引发以下异常:
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);
}
您将不得不以某种方式获取此控制器的策略id,并使用它来标识适当的中间件。接受的答案对于Auth 1是好的,但在Auth 2中,该方法被贬低,因此请使用扩展方法
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
参考:
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);