【问题标题】:How do I log out when using identity server?使用身份服务器时如何注销?
【发布时间】:2019-04-04 09:43:39
【问题描述】:

请查看代码 vlow,它取自我在 MVC 应用程序中的 Startup.cs

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            services.AddCustomMvc(Configuration)
                .AddHttpClientServices(Configuration);

            services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
                .AddCookie("Cookies")
                .AddOpenIdConnect("oidc", options =>
                {
                    options.SignInScheme = "Cookies";

                    options.Authority = "http://localhost:5000"; 
                    options.RequireHttpsMetadata = false;

                    options.ClientId = "mvc2";
                    options.ClientSecret = "secret";
                    options.ResponseType = "code id_token";

                    options.SaveTokens = true;
                    options.GetClaimsFromUserInfoEndpoint = true;

                    options.Scope.Add("MyAPI1");
                    options.Scope.Add("MyAPI2");
                    options.Scope.Add("offline_access");
                });

        }

身份验证和授权在 MyAPI1 和 myAPI2 中正常工作,但我无法注销。我试过这个:

await HttpContext.SignOutAsync("Cookies");

还有这个:

await HttpContext.SignOutAsync();

用户未注销。用户如何注销?

【问题讨论】:

    标签: c# asp.net-core identityserver4


    【解决方案1】:

    您可以将以下代码添加到某些控制器以触发注销:

    public IActionResult Logout()
    {
        return SignOut("Cookies", "oidc");
    }
    

    这将清除本地 cookie,然后重定向到 IdentityServer。 IdentityServer 将清除其 cookie,然后为用户提供返回 MVC 应用程序的链接。还要记得在 IDS 的客户端配置中设置PostLogoutRedirectUris

    【讨论】:

    猜你喜欢
    • 2013-08-28
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-25
    • 2018-01-24
    • 2020-04-16
    • 2021-03-29
    • 1970-01-01
    相关资源
    最近更新 更多