我的标识服务器正在使用identityserver4框架(http://localhost:9000)。我如下在Identity Server上注册客户端。无法注销ASP.NET Core 2应用程序上Identityserver4的OpenIdConnect身份验证
clients.Add(
new Client
{
ClientId = "customer.api",
ClientName = "Customer services",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
RequireConsent = false,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:60001/signin-oidc" },
PostLogoutRedirectUris = { "http://localhost:60001/signout-callback-oidc" },
ClientSecrets = new List<Secret>
{
new Secret("testsecret".Sha256())
},
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
IdentityServerConstants.StandardScopes.OfflineAccess,
"customerprivatelinesvn.api",
},
AllowOfflineAccess = true,
AlwaysIncludeUserClaimsInIdToken = true,
AllowedCorsOrigins = { "http://localhost:60001" }
});
这是我的客户端应用程序(http://localhost:60001)上的身份验证。
private void AddAuthentication(IServiceCollection services)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie()
.AddOpenIdConnect("oidc", options =>
{
Configuration.GetSection("OpenIdConnect").Bind(options);
});
}
"OpenIdConnect": {
"SignInScheme": "Cookies",
"Authority": "http://localhost:9000/",
"RequireHttpsMetadata": false,
"ClientId": "customer.api",
"ClientSecret": "testsecret",
"Scope": [ "customerprivatelinesvn.api", "offline_access" ],
"CallbackPath": "/signin-oidc",
"ResponseType": "code id_token token",
"GetClaimsFromUserInfoEndpoint": true,
"SaveTokens": true
}
HomeController的客户端应用程序的
[Authorize]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
我尝试实现signout动作如下
public class AccountController : Controller
{
public async Task<IActionResult> Signout()
{
await HttpContext.SignOutAsync("Cookies");
await HttpContext.SignOutAsync("oidc");
return RedirectToAction("Index", "Home");
}
}
但是当用户注销时,它不会调用身份服务器的终端端点。我看着提琴手的流量,没有要求识别服务器。
我的期望是,当用户登录时,它会调用endsession身份服务器的端点,然后重定向到注销身份服务器的链接如下。
我们可以通过调用OwinContext signout
private void LogoutOwin(IOwinContext context)
{
context.Authentication.SignOut();
}
但signout方法不能在ASP.NET工作了核心2
做到这一点很容易地在MVC应用程序注意:我从AJAX帖子调用注销操作,因为我的客户端应用程序是角度为5的应用程序。
有谁知道如何在ASP.NET Core 2上正确实现登出?
非常感谢。
问候,
凯文