我的標識服務器正在使用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上正確實現登出?
非常感謝。
問候,
凱文