Blu*_*uds 6 asp.net openid-connect
主要问题是我找不到从 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
});
Run Code Online (Sandbox Code Playgroud)
本地运行的 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",
},
},
Run Code Online (Sandbox Code Playgroud)
我能够像这样登录并在 MVC 中的控制器视图上显示声明
[Authorize]
public IActionResult About()
{
return View((User as ClaimsPrincipal).Claims);
}
Run Code Online (Sandbox Code Playgroud)
显示的视图是这样的。注意没有id_token
我可以使用下面给出的 cookie 注销
public async Task<IActionResult> LogOut()
{
await HttpContext.Authentication.SignOutAsync("Cookies");
return Redirect("~/");
}
Run Code Online (Sandbox Code Playgroud)
但问题是我找不到从 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 的帮助下)。
我有以下问题:
对于注销,您是否尝试过-
HttpContext.Authentication.SignOutAsync("oidc");
Run Code Online (Sandbox Code Playgroud)
在您客户端的注销操作中?