2017-02-28 3 views
0

하늘빛 광고 b2c에서 webapp을 로그 아웃하고 싶습니다. 나는이 샘플 https://www.janaks.com.np/azure-ad-identity-provider-in-aspnet-core-application/에서 제안 된 것과 같이 다음을 시도했다. Startup.cs에서 다음과 같은 구성으로Azure 광고 로그 아웃

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

:

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 
}); 

하지만 던져 질 것이다 예외 다음과 같은 웹 애플리케이션에서 로그 아웃 할 때 :

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

감사를 도와 . 당신은 어떻게 든이 컨트롤러에 정책 ID를 얻고 적절한 미들웨어를 식별하는 데 사용해야합니다

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

:

답변

2

당신은 사용자가 설정 한 인증 방식을 확인해야합니다.

0

승인 된 대답은 Auth 1에는 좋지만 Auth 2에서는 해당 메소드가 감가 상각되므로 확장 방법을 사용하십시오.

await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); 

참조 : https://github.com/aspnet/Announcements/issues/232

관련 문제