我在使用 cas 和 jwt 状态处理我的 SSO 登录的逻辑方面遇到了一些麻烦。
开始之前:用户对我的应用程序进行身份验证,需要访问 cas,在 url 中包含需要获得访问权限的应用程序名称作为参数,例如:myapp.com
登录后,用户将使用 302 重定向到我的应用程序,并在 URL 中附加 JWT: myapp.com/?service=JWT-blablabla
这就是我想象应用程序的流程来检查用户是否已登录或他是否带着 jwt
我有一些问题:
如果用户附带了一个有效的 jwt,但他在 localstorage 中仍然有一个有效的 JWT,那么哪个 JWT 具有最新鲜的过期时间的优先级,或者旧的 JWT 会被 cas 自动失效?请记住,jwt 需要由我的后端验证
In my http calls I append my bearer jwt, the problem is that I cache my http calls, if the jwt expire and the user don't make http calls, how can I handle that? I need to logout the user I can't wait to make an http call and tell him it's invalid or should I?
Having implemented SSO recently myself, here are some answers to your questions:
The newest token should take priority, but why is this even happening, i.e. why is there a new jwt token in the url? If the user goes to the login page while they still have a valid jwt token in local storage, they should be redirected to your home page (or somewhere), ps. you cannot invalidate a jwt token.
令牌过期后,您的服务器应返回 401 响应;这是你应该注意的。检查用户在本地存储中是否有 jwt 令牌,如果他们也收到 401,则您知道令牌已过期,因此调用您的 api 以刷新令牌,而无需将用户重定向到登录页面。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句