【发布时间】:2016-06-12 10:37:34
【问题描述】:
我尝试通过 SignOut 删除,但它没有被删除或过期。
var authentication = HttpContext.Current.GetOwinContext().Authentication;
authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie,
Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie,
Microsoft.AspNet.Identity.DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie,
Microsoft.AspNet.Identity.DefaultAuthenticationTypes.TwoFactorCookie);
authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);
authentication.SignOut();
我尝试在许多博客(msdn、堆栈溢出等)中找到解决方案,但尚未看到解决方案。
我正在通过以下方式生成令牌:
// Set claim
var identityType = new GenericIdentity(userName, Config.Constants.BASICIDENTITYTYPE);
string[] roles = null;
var principal = new GenericPrincipal(identityType, roles);
Thread.CurrentPrincipal = principal;
if (HttpContext.Current != null)
{
HttpContext.Current.User = principal;
}
var identity = new ClaimsIdentity(StartUp.OAuthBearerOptions.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
identity.AddClaim(new Claim(Config.Constants.USERNAME, userName));
identity.AddClaim(new Claim(Config.Constants.USERID, userId.ToString()))
// Generate ticket
AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
var currentUtc = new SystemClock().UtcNow;
ticket.Properties.IssuedUtc = currentUtc;
TimeSpan expiryTime = Constants.TOKEN_EXPIRY_TIME_SECOND);
ticket.Properties.ExpiresUtc = currentUtc.Add(expiryTime);
return StartUp.OAuthBearerOptions.AccessTokenFormat.Protect(ticket);
【问题讨论】:
-
“Owin 令牌”是什么意思?会话 Cookie?
-
@Brent Schmaltz 我想要删除或过期 Owin 令牌。
-
你的 startup.cs 是什么样的?
-
@Brent Schmaltz:添加了关于我如何生成令牌的问题部分。感谢布伦特阅读..
标签: c# asp.net-mvc asp.net-web-api owin