OpenIDConnect AspNetCore 注销使用 id_token

OpenIDConnect AspNetCore Logout using id_token

主要问题是我找不到从 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 中的控制器视图上显示声明

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

然后显示的视图是这样的。注意没有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 的提琴手那里得到了 id_token 然后触发了 identityServer 的注销(在上面给出的 url 的帮助下)。

我有以下问题:

  1. 如何在代码中得到id_token? (而不是从 fiddler 手动复制)
  2. 有没有更好的注销方式?或者是否有一个 AspnetCore/Oidc 框架方法来注销(它又用正确的参数调用正确的服务器 api)?
  3. 我可以多次注销和登录,但是 id_token 在 fiddler 上看到的是一样的。例如:Bob 用户,Alice 用户都有相同的id_token。 Cookie 已被清除,每次在视图上显示不同的用户时 id_token 仍然相同。每个 login/user 的 id_token 不应该不同吗?
  4. 注销 url 即使我给出一个随机字符串 id_token 也能正常工作。这是否意味着 IdentityServer4 注销功能无法基于 id_token 工作?

关于注销,你试过吗-

HttpContext.Authentication.SignOutAsync("oidc");

在您客户的注销操作中?