首页 文章

使用id_token的OpenIDConnect AspNetCore注销

提问于
浏览
4

主要问题是我找不到从identityServer4注销的正确方法 .

详细说明:

客户端Web应用程序startup.cs包含以下代码

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationScheme = "Cookies",
            AutomaticAuthenticate = true
        });
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
        {
            AuthenticationScheme = "oidc",
            SignInScheme = "Cookies",
            Authority = "http://localhost:1941/",//local identityServer4
            ClientId = "testsoft",
            ClientSecret = "secret",
            ResponseType = "code id_token token",
            GetClaimsFromUserInfoEndpoint = true,
            RequireHttpsMetadata = false,
            Scope = { "openid", "profile", "email" },
            TokenValidationParameters = new TokenValidationParameters()
            {
                NameClaimType = "name",
                RoleClaimType = "role"
            },
            AutomaticAuthenticate = false,
           AutomaticChallenge = true
    });

在本地运行的IdentityServer4具有如下添加的客户端

new Client
            {
                ClientId = "testsoft",
                ClientName = "testsoft",
                ClientSecrets = new List<Secret>
                {
                    new Secret("secret".Sha256())
                },
                ClientUri = "http://localhost:55383/",//clientside web application url
                AllowedGrantTypes = GrantTypes.Hybrid,
                AllowAccessTokensViaBrowser = true,
                RedirectUris = new List<string>
                {
                    "http://localhost:55383/signin-oidc"
                },
                RequireConsent = false,
                AllowedScopes = new List<string>
                {
                    StandardScopes.OpenId.Name,
                    StandardScopes.Profile.Name,
                    StandardScopes.Email.Name,
                    StandardScopes.Roles.Name,
                    StandardScopes.OfflineAccess.Name,

                    "api1", "api2",
                },
            },

我能够像这样登录并在MVC中的Controller-View上显示声明

[Authorize]
    public IActionResult About()
    {
        return View((User as ClaimsPrincipal).Claims);
    }

显示的视图是这样的 . 请注意,没有id_token

And the view displayed was like this. Note that there is no id_token

我可以使用下面给出的cookie注销

public async Task<IActionResult> LogOut()
    {

        await HttpContext.Authentication.SignOutAsync("Cookies");
        return Redirect("~/");
    }

但问题是我找不到从IdentityServer注销的方法 . 我越来越接近使用 /connect/endsession?id_token_hint=...&post_logout_redirect_uri=https://myapp.com

但我找不到在代码中获取原始id_token的方法 . 在上面给出的About()方法中,我只得到声明(我认为是id_token的解密内容),并且在那些声明列表中没有可见的id_token . 但不知何故设法从这个url http://localhost:55383/signin-oidc的fiddler获取id_token然后在identityServer上注销(在上面给出的url的帮助下) .

我有以下问题:

  • 如何在代码中获取id_token? (而不是来自提琴手的手动复制)

  • 有更好的退出方式吗?或者是否有一个AspnetCore / Oidc框架方法来注销(反过来用正确的参数调用正确的服务器api)?

  • 我能够多次注销并登录,但在fiddler上看到id_token是相同的 . 例如:Bob用户,Alice用户都具有相同的id_token . Cookie被清除,每次在视图上显示不同的用户时,id_token仍然相同 . 每个登录/用户不应该id_token不同吗?

  • 注销网址即使我将随机字符串作为id_token也可以使用 . 这是否意味着IdentityServer4注销功能不能基于id_token工作?

1 回答

  • 1

    要退出,你试过 -

    HttpContext.Authentication.SignOutAsync("oidc");
    

    在您的客户的注销行动?

相关问题