我在外部身份验证服务器中使用OWIN中间件,我的应用程序使用OAuth授权代码授权流进行身份验证.
我可以重定向到身份验证服务器,针对外部提供商(Google)进行身份验证,并使用已登录的用户和应用程序Cookie设置重定向回我的客户端应用程序,但是当我尝试在我调用该AuthenticationManager.SignOut
方法后注销cookie时.
我的cookie选项Startup.Auth.cs
是:
var cookieOptions = new CookieAuthenticationOptions { Provider = cookieProvider, AuthenticationType = "Application", AuthenticationMode = AuthenticationMode.Passive, LoginPath = new PathString("/Account/Index"), LogoutPath = new PathString("/Account/Logout"), SlidingExpiration = true, ExpireTimeSpan = TimeSpan.FromMinutes(30), }; app.UseCookieAuthentication(cookieOptions); app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ExternalCookie); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
我的登录方式:
var loginInfo = await AuthManager.GetExternalLoginInfoAsync(); SignInManager.ExternalSignInAsync(loginInfo, true); var identity = AuthManager.AuthenticateAsync(DefaultAuthenticationTypes.ExternalCookie).Result.Identity; if (identity != null) { AuthManager.SignIn( new AuthenticationProperties {IsPersistent = true}, new ClaimsIdentity(identity.Claims, "Application", identity.NameClaimType, identity.RoleClaimType)); var ticket = AuthManager.AuthenticateAsync("Application").Result; var identity = ticket != null ? ticket.Identity : null; if (identity == null) { AuthManager.Challenge("Application"); return new HttpUnauthorizedResult(); } identity = new ClaimsIdentity(identity.Claims, "Bearer", identity.NameClaimType, identity.RoleClaimType); AuthManager.SignIn(identity); } return Redirect(Request.QueryString["ReturnUrl"]);
退出方法:
var authTypeNames = new List(); authTypeNames.Add("Google"); authTypeNames.Add("Application"); authTypeNames.Add("Bearer"); authTypeNames.Add(DefaultAuthenticationTypes.ExternalCookie); Request.GetOwinContext().Authentication.SignOut(authTypeNames.ToArray());
我查看了其他问题,如: OWIN身份验证,过期当前令牌以及删除cookie 和 OWIN - Authentication.SignOut()不会删除cookie
没有运气.我知道我可以通过设置一个负的到期日来手动删除cookie,但如果可能的话,我更愿意使用内置方法.
如何在我退出时删除应用程序Cookie?