Ste*_*eve 19 c# authentication cookies owin asp.net-identity
我在外部身份验证服务器中使用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);
Run Code Online (Sandbox Code Playgroud)
我的登录方式:
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"]);
Run Code Online (Sandbox Code Playgroud)
退出方法:
var authTypeNames = new List<string>();
authTypeNames.Add("Google");
authTypeNames.Add("Application");
authTypeNames.Add("Bearer");
authTypeNames.Add(DefaultAuthenticationTypes.ExternalCookie);
Request.GetOwinContext().Authentication.SignOut(authTypeNames.ToArray());
Run Code Online (Sandbox Code Playgroud)
我查看了其他问题,如: OWIN身份验证,过期当前令牌以及删除cookie 和 OWIN - Authentication.SignOut()不会删除cookie
没有运气.我知道我可以通过设置一个负的到期日来手动删除cookie,但如果可能的话,我更愿意使用内置方法.
如何在我退出时删除应用程序Cookie?
小智 -3
如果您有任何母版页,请添加以下标签。也许这会有帮助。
<meta http-equiv="Cache-control" content="no-cache" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3434 次 |
| 最近记录: |