撤销承载令牌和刷新令牌 - ServiceStack [英] Revoking Bearer Token and Refresh Token - ServiceStack

查看:50
本文介绍了撤销承载令牌和刷新令牌 - ServiceStack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 Angular 应用强制执行单用户会话功能,因为我的客户与其同事共享一个帐户.

I want to enforce a single user session feature for my Angular app because my customers share a single account with their coworkers.

目前的问题,与我的实施有关.正在撤销存储在客户端本地存储的有效令牌,尤其是有效的刷新令牌.

The issue currently, with my implementation. is revoking a valid token stored a client's local storage, particularly a valid Refresh token.

场景是:

  1. 用户 1 使用有效的用户名和密码登录,不记名令牌将在一个小时后过期,刷新令牌将在两周后过期
  2. 用户 2,两小时后使用相同的用户名和密码.用户 2 被提示他们已登录到另一台设备,并询问他们是否希望使该会话过期并开始新会话.
  3. 用户 2 说是,现在用户 1 的会话无效.

问题是用户 1 仍然有一个有效的刷新令牌.

The problem is that User 1 still has a valid Refresh token.

我无法撤销这个刷新令牌.我的 Auth API 将接受有效,我不知道它是用户 1 还是用户 2 的刷新令牌.

I have no way revoke this refresh token. My Auth API will accept is valid and I will not know whether it is User 1 or User 2's refresh token.

我是否需要开始在我的数据库中存储刷新令牌值来解决这个问题?我还认为我可以为 User1 和 User2 使用不同的 JwtAuthKeyBase64,作为使 User1 的令牌无效的一种方法,但这似乎不是使用 ServiceStack JwtAuthProvider 的好方法.

Do I need to start storing refresh token values in my database to resolve this issue? I also thought I could use a different JwtAuthKeyBase64 for User1 and User2, as a way to invalidate User1's token but this doesn't seem like a good way to be using the ServiceStack JwtAuthProvider.

推荐答案

JWT RefreshToken 用于联系 Auth Server 以获取新的 JWT Bearer Token.如果用户仍然具有访问权限,它只会返回一个 BearerToken,因此您可以通过填充 UserAuth.LockedDate 来锁定用户帐户,这将阻止用户检索新的 JWT 不记名令牌.

The JWT RefreshToken is used to contact the Auth Server to fetch a new JWT Bearer Token. It will only return a BearerToken if the User still has Access so you can lock the User Account by populating UserAuth.LockedDate which will prevent the user from retrieving a new JWT Bearer Token.

如果您想要更多自定义验证,您可以实施IUserSessionSource 并在 GetUserSession() 中抛出异常以返回错误响应而不是 JWT 承载令牌.

If you want more custom validation you can implement IUserSessionSource and throw an Exception in GetUserSession() to return an Error Response instead of the JWT Bearer Token.

这篇关于撤销承载令牌和刷新令牌 - ServiceStack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆