【发布时间】:2017-01-22 23:00:51
【问题描述】:
我已经实现了 IdentityServer3 来创建我自己的身份服务器,该服务器托管在 azure 云上。 我有几个客户端应用程序通过我的身份服务器进行身份验证。这两个应用程序都是 MVC 应用程序。其中一个在 Azure 上作为 cloudapp 运行,另一个在我的本地计算机上并在 localhost 上运行。正如预期的那样,当我登录其中一个时,我会自动登录到另一个。 但是,当我退出其中任何一个时,我不会自动从在同一浏览器中打开的另一个退出。
任何帮助将不胜感激...:)
以下是我的客户端应用程序的身份验证配置
public void ConfigureAuth(IAppBuilder app)
{
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
var options = new OpenIdConnectAuthenticationOptions
{
ClientId = ConfigHelper.GetAppSetting(ConfigConstants.ClientIdKeyName),
Authority = ConfigHelper.GetAppSetting(ConfigConstants.IdpUriKeyName),
RedirectUri = "https://myclient1.cloudapp.net/",
PostLogoutRedirectUri = "https://myclient1.cloudapp.net/account/logoutcallback",
ResponseType = "code id_token token",
Scope = "openid profile address roles email",
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "role"
},
SignInAsAuthenticationType = "Cookies",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = async n =>
{
var tokenClient = new TokenClient(
"https://myidp.cloudapp.net/core/connect/token",
"myclient-1",
"myclient-1-secret");
var tokenResponse = await tokenClient.RequestAuthorizationCodeAsync(
n.Code, n.RedirectUri);
if (tokenResponse.IsError)
{
throw new Exception(tokenResponse.Error);
}
var id = new ClaimsIdentity(n.AuthenticationTicket.Identity.Claims, n.AuthenticationTicket.Identity.AuthenticationType);
n.AuthenticationTicket = new AuthenticationTicket(new ClaimsIdentity(id.Claims, n.AuthenticationTicket.Identity.AuthenticationType, "name", "role"),
n.AuthenticationTicket.Properties);
}
}
};
app.UseOpenIdConnectAuthentication(options);
}
我在打电话
this.Request.GetOwinContext().Authentication.SignOut();
注销身份服务器
当它回到我的客户端应用程序时,它涉及
public ActionResult LogoutCallback()
{
HttpCookie cookie = new HttpCookie("SecureCookieName");
cookie.HttpOnly = true;
cookie.Expires = new DateTime(1999, 10, 12);
Response.Cookies.Remove("SecureCookieName");
Response.Cookies.Add(cookie);
SessionManager.KillSession(); //Custom stuff to clear the session of client application.
return RedirectToAction("Index", "Home");
}
【问题讨论】:
-
您的 IdentityServer3 客户端配置是什么样的?具体来说,为您的客户设置了哪些 LogoutUri 值?
-
对不起..我的错..我忘了用实际值替换我的常量。我已经更新了帖子。请再看一遍。提前感谢您的帮助。
标签: asp.net-mvc single-sign-on owin logout identityserver3