使用 OpenID 注销的 SSO 登录不成功

问题描述 投票:0回答:1

我正在使用下面的代码片段登录 Microsoft Azure,此代码是我在 StartupAuth.cs 中编写的用于签名用户的代码。

app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions());

app.UseOpenIdConnectAuthentication(
    new OpenIdConnectAuthenticationOptions
    {
        ProtocolValidator = new CustomOpenIdConnectProtocolValidator(false),
        ClientId = clientId,
        Authority = authority,
        PostLogoutRedirectUri = postLogoutRedirectUri,
       

        Notifications = new OpenIdConnectAuthenticationNotifications()
        {
            AuthenticationFailed = (context) =>
            {
                return System.Threading.Tasks.Task.FromResult(0);
            }
        }

    }
    );
app.UseStageMarker(PipelineStage.Authenticate); 

但是,当注销时,我使用下面的代码,但它不起作用,我错过了什么?

var postLogoutRedirectUri = "https://localhost/PALMS-8.1/";
HttpContext.Current.GetOwinContext().Authentication.SignOut(new AuthenticationProperties { RedirectUri = postLogoutRedirectUri },
    OpenIdConnectAuthenticationDefaults.AuthenticationType,
    CookieAuthenticationDefaults.AuthenticationType);

注销时我无法注销,不知道为什么是由于 Cross 政策或其他原因。

azure-active-directory single-sign-on openid-connect
1个回答
0
投票
Open ID Connect 中的

注销过程是通过清除应用程序 cookie 或删除用户会话来实现的。您需要将活动会话重定向到 post_logout_redirect_uri。否则注销将不起作用。

您可以按照示例

此处进行操作,其中包括完整的实现和用途:

HttpContext.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
如果您需要设置 post_logout_redirect_uri 以将用户定向到特定 URL,它还需要与您在应用程序注册中配置的 URL 之一相匹配。

© www.soinside.com 2019 - 2024. All rights reserved.