【问题标题】:How to expire token for user in token based authentication for Web API如何在基于令牌的 Web API 身份验证中使用户的令牌过期
【发布时间】:2019-03-13 02:15:33
【问题描述】:

最近我在Article 之后为我的 Web API 项目创建了基于令牌的身份验证,我可以在这里创建令牌并验证令牌。但是当用户注销时,我们正在从用户设备中删除令牌,如果用户在我们删除该令牌之前保存了令牌,它仍然有效,直到它到达到期时间,这导致 API 的安全性较低

任何人都可以建议我如何使颁发的令牌过期。(因为我们有庞大的用户数据库,我们不会在数据库中存储任何令牌。)

【问题讨论】:

  • 这篇文章描述了问题和可能的方法。保持令牌生命周期短,在需要时刷新,可能在某种快速访问存储中维护“令牌撤销列表” - stackoverflow.com/a/23089839/1538039

标签: asp.net asp.net-web-api asp.net-web-api2 access-token


【解决方案1】:
You can clear cookies and entire session if exists any !


Request.GetOwinContext().Authentication.SignOut();

 Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);

HttpContext.Current.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie)
猜你喜欢
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
  • 2016-07-31
  • 2017-05-30
  • 2016-06-09
  • 1970-01-01
  • 2015-10-14
相关资源
最近更新 更多