【发布时间】:2018-05-09 10:53:54
【问题描述】:
我的 Identity Server 正在使用 identityserver4 框架 (http://localhost:9000)。我在 Identity Server 上注册了客户端,如下所示。
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();
}
}
我尝试执行如下退出操作
public class AccountController : Controller
{
public async Task<IActionResult> Signout()
{
await HttpContext.SignOutAsync("Cookies");
await HttpContext.SignOutAsync("oidc");
return RedirectToAction("Index", "Home");
}
}
但是当用户退出时,它不会调用身份服务器的 endsession 端点。我看fiddler的流量,没有对身份服务器的请求。
我的期望是当用户注销时,它会调用身份服务器的 endsession 端点并重定向到身份服务器的注销链接,如下所示。
我们可以通过调用 OwinContext 注销在 MVC 应用程序上轻松完成此操作
private void LogoutOwin(IOwinContext context)
{
context.Authentication.SignOut();
}
但是注销方法在 ASP.NET Core 2 上不再起作用。
注意:我从 AJAX 帖子调用注销操作,因为我的客户端应用程序是 Angular 5 应用程序。
有谁知道如何在 ASP.NET Core 2 上正确实现注销?
非常感谢。
问候,
凯文
【问题讨论】:
标签: c# asp.net-core-2.0 identityserver4