刷新令牌 - 多个客户端的服务器端存储和撤销

Refresh Tokens - Server Side Storage And Revoking For Multiple Clients

我开始使用 ASOS (AspNet.Security.OpenIdConnect.Server) 框架进行基于令牌的身份验证。

我已经完成了访问令牌的生成和检索,现在要继续刷新令牌位。

我的问题是:

另外,撤销刷新令牌的一般流程是什么? 是不是就像从存储它的地方删除它一样简单?

谢谢。

Should I just store the clientID and the hashed and salted refresh token in a database (Along with utility fields, such as an expiration date)?

我推荐的方法是使用 ASOS 附加到它创建的所有令牌的票证标识符。您可以通过 context.Ticket.GetTokenId()context.Ticket.ExpiresUtc.

SerializeRefreshToken 事件中检索刷新令牌标识符和到期日期

注意:默认标识符是 GUID,但您可以使用 context.Ticket.SetTokenId("token identifier").

替换它

Specifically, I mean what if 1 of the client's access tokens expires, but their refresh token has also expired? Of course they can go to the token endpoint to get a new access token and refresh token at the same time, but then what about the other instances for that clientID?

这实际上取决于您的应用程序要求以及您如何实现它。您可以自由地将刷新令牌视为完全独立的,或者相反,相互依赖的。这种逻辑通常会发生在 HandleTokenRequest.

Also, what is the common process of revoking the refresh tokens? Is it as simple as just deleting it from wherever you're storing it?

如果您使用默认令牌格式(超过推荐的格式),刷新令牌将被视为有效,直到它们过期。您可以通过数据库查找来检查令牌是否已从 HandleTokenRequest 中撤销(您可以使用 context.Ticket.GetTokenId() 获取刷新令牌标识符)