【发布时间】:2021-06-12 07:24:46
【问题描述】:
我在成功登录后发出访问令牌和刷新令牌。它们都保存在浏览器中的相同站点 cookie 中。自定义中间件将在身份验证过程之前将令牌放入 Authorization 标头中。该中间件还将检查访问令牌是否过期,如果是,它将尝试刷新令牌,如果验证将保存两个新的 cookie(新的刷新令牌和新的访问令牌)并将新生成的访问令牌与当前要求。
这是我们应该如何实现刷新令牌的方式吗?如果我想将特定的刷新令牌列入黑名单,是否应该将所有刷新令牌保存在数据库中?
string auth = httpContext.Request.Cookies["AuthToken"];
if(string.IsNullOrEmpty(auth))
{
httpContext.Request.Headers.Add("Authorization", $"AuthorizationCookieNotFound");
return _next(httpContext); //That token wont be accepted i just
// put it there for the sake of demonstration
}
httpContext.Request.Headers.Add("Authorization", $"Bearer {auth}");
return _next(httpContext);
【问题讨论】:
标签: asp.net-core .net-core jwt asp.net-core-webapi