10000 token怎么刷新呢 · Issue #3 · freew01f/securing-spring-boot-with-jwts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

token怎么刷新呢 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
deep1981 opened this issue Aug 29, 2019 · 2 comments
Open

token怎么刷新呢 #3

deep1981 opened this issue Aug 29, 2019 · 2 comments

Comments

@deep1981
Copy link

@freew01f 谢谢代码,很清楚。

我实际中,在user登陆后生成token保存到数据库,下一次登陆要求user生成新的token,并更新数据库里的token;之前的token作废。那么如何刷新token呢,现在用前后两个token都可以通过验证(两个token都没有逾期)

谢谢

@deep1981
Copy link
Author

@freew01f 谢谢代码,很清楚。

我实际中,在user登陆后生成token保存到数据库,下一次登陆要求user生成新的token,并更新数据库里的token;之前的token作废。那么如何刷新token呢,现在用前后两个token都可以通过验证(两个token都没有逾期)

谢谢

又看了一遍,是否是在TokenAuthenticationService里面的getAuthentication做相应的处理?
在这个方法可以获取当前token,然后解析拿出usernamen,这个在usertoken的表里是可以拿出当时保存的token,然后两个对比,再进一步操作?

因为看到

return user != null ?
new UsernamePasswordAuthenticationToken(user, null, authorities) :
null;
只要不过期,更新前后的token肯定都是能返回通过认证。

但如何让前一个token作废呢

@freew01f
Copy link
Owner

jwt不是这么玩的
jwt的认证服务签发token 直接发给client 服务端并不存储
c端自己拿着token 每次挂上 访问受限接口就好了
你存token到服务端没意义 因为每次客户端都发给你
你登录10次 就会生成10个 都有效 因为本身就是合法获取 为啥要让之前的失效?

如果你想让某些失效 就要建立黑名单 我觉得没啥意义
为什么用jwt 就是不中心化存储 token 或者 session
如果你这样 不又中心化存储回话信息了吗

我觉得我说明白了

495D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0