C# OWIN身份验证,使当前令牌过期并删除cookie
我有一个用于身份验证的OWIN中间件。我们有两种类型的身份验证。 第一种类型是使用以下配置的承载令牌C# OWIN身份验证,使当前令牌过期并删除cookie,c#,authentication,owin,C#,Authentication,Owin,我有一个用于身份验证的OWIN中间件。我们有两种类型的身份验证。 第一种类型是使用以下配置的承载令牌 var OAuthOptions = new OAuthAuthorizationServerOptions { AuthenticationType = DefaultAuthenticationTypes.ExternalBearer, TokenEndpointPath = new PathString("/Token"), Pro
var OAuthOptions = new OAuthAuthorizationServerOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true,
AccessTokenFormat = new SecureTokenFormatter(GetMachineKey())
};
第二种类型使用身份验证cookie进行外部登录
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
CookieHttpOnly = true,
CookieSecure = CookieSecureOption.SameAsRequest,
CookieName = ".AspNet." + DefaultAuthenticationTypes.ExternalCookie,
ExpireTimeSpan = TimeSpan.FromMinutes(5),
TicketDataFormat = new SecureTokenFormatter(GetMachineKey())
});
当用户注销时,我们实际上发出两次注销
Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie);
及
对于第一个,我希望看到.AspNet.ExternalCookie Cookie从浏览器中删除,而不是从浏览器中删除。
对于第二个,我希望我的令牌无效,并且User.Current.Identity=null,而不是
那我该怎么办呢
1) 物理注销当前会话的当前标识?
2) 是否从浏览器中删除外部Cookie?我遇到了与您相同的问题,经过3天的搜索,我找到了asnwer(有点…) 在您的注销中尝试这些代码行中的一行(且仅一行)。(它们都对我有用,但我正在使用第一个,但示例越多越好,对不对??) 这一问题在本文中得到了很好的描述,但它没有提供一个有效的解决方案(至少对我来说没有)
我通过以下方法解决了同样的问题:Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.applicationcokie);FederatedAuthentication.SessionAuthenticationModule.SignOut();
Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalBearer);
Request.GetOwinContext().Authentication.SignOut();
Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);
HttpContext.Current.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);