简体   繁体   English

从 OIDC 客户端注销不使用 IdentityServer4

[英]Sign out from OIDC client not working with IdentityServer4

I'm currently working on a .NET 5 application using IdentityServer4.我目前正在使用 IdentityServer4 开发 .NET 5 应用程序。

I use the Authorization Code + PKCE flow to sign in - unfortunately the logout seems not to work correctly on localhost .我使用授权码 + PKCE 流程登录 -不幸的是,注销似乎无法在 localhost 上正常工作

My application landscape looks like this:我的应用程序环境如下所示:

  • App (WebApp)应用程序(网络应用程序)
  • IdentityServer4身份服务器4

My Client definition in IdentityServer4 looks like this:我在 IdentityServer4 中的客户端定义如下所示:

// Authorization Code + PKCE Flow
new Client
{
    ClientId = "oidcClient",
    ClientName = "Example App",
    ClientSecrets = { new Secret("secret".Sha256()) },

    RedirectUris = { "https://localhost:44301/signin-oidc" },
    PostLogoutRedirectUris = { "https://localhost:44301/signout-callback-oidc" },

    AllowedGrantTypes = GrantTypes.Code,
    RequirePkce = true,
    RequireClientSecret = true,
    
    AllowedScopes = 
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email,
        IdentityServerConstants.StandardScopes.OfflineAccess,
        "roles",
    },

    AllowPlainTextPkce = false,
},

My OIDC connect on the client app looks like this:我在客户端应用程序上的 OIDC 连接如下所示:

services.AddAuthentication(options => 
{
    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options => 
{
    options.Authority = "https://localhost:5001";
    options.RequireHttpsMetadata = true;
    options.ClientId = "oidcClient";
    options.ClientSecret = "secret";

    options.ResponseType = "code";
    options.UsePkce = true;
    options.ResponseMode = "query";

    options.Scope.Add("offline_access");
    options.Scope.Add("roles");
    
    options.SaveTokens = true;
});

The logout method in my WebApp HomeController looks like this:我的 WebApp HomeController 中的注销方法如下所示:

public async Task<IActionResult> Logout()
{
    await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
    await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);

    return new SignOutResult(new[] { OpenIdConnectDefaults.AuthenticationScheme, CookieAuthenticationDefaults.AuthenticationScheme });
}

The IdentityServer4 Logs tell me on login => Login Success and on Logout => Logout Success. IdentityServer4 日志告诉我登录 => 登录成功和注销 => 注销成功。

This is strange - the application stays logged in all the time.这很奇怪——应用程序一直保持登录状态。

When I logout and return to the WebApp Home Index page I'm still logged in - although I should be logged out.当我注销并返回 WebApp 主页索引页面时,我仍然登录 - 尽管我应该注销。

Do you know how to configure properly the logout in an IdentityServer4 OIDC application?您知道如何在 IdentityServer4 OIDC 应用程序中正确配置注销吗?

Do you know how to solve this issue?你知道如何解决这个问题吗?

The Logout method should never return anything. Logout 方法不应该返回任何东西。 Because if you do, you override the redirect that the SignOut methods generate internally.因为如果这样做,您将覆盖 SignOut 方法在内部生成的重定向。

A better way is to do this:更好的方法是这样做:

public async Task DoLogout()
{
    await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
    await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过oidc-client登录IdentityServer4时出现InvalidOperationException - InvalidOperationException when signing in to IdentityServer4 via oidc-client 使用oidc-client和IdentityServer4在不同的域中登录 - SignIn with oidc-client and identityServer4 in different domain IdentityServer4 OIDC如何知道从配置重定向到的位置 - IdentityServer4 How does oidc know where to redirect to from configuration MVC Client和Api在IdentityServer4中一起工作 - MVC Client and Api working together in IdentityServer4 如何使用结束会话端点IdentityServer4注销? - How to sign-out using the end session endpoint IdentityServer4? 是否可以将 IdentityServer4 中的用户注销为其他用户? - Is it possible to sign out a User in IdentityServer4 as a different user? IdentityServer4 使用带有 API 的客户端凭据工作流(或尝试模拟 OIDC 调用) - IdentityServer4 Using Client Credential Workflow with an API (Or trying to emulate OIDC calls) ASP.Net Core-IdentityServer4客户端凭据授权不起作用 - ASP.Net Core - IdentityServer4 client credentials authorization not working 使用 IdentityServer4 保护胖客户端 - Securing thick client with IdentityServer4 如果服务器重新启动,我可以从客户端请求 IdentityServer4 令牌吗? - Can I request IdentityServer4 tokens from client if server was rebooted?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM