繁体   English   中英

如何在 Spring Boot 中实现刷新令牌

[英]How to implement refresh token in Spring Boot

我已经按照本指南https://auth0.com/blog/implementing-jwt-authentication-on-spring-boot/在我的 Web 应用程序中实现访问令牌,它工作正常。 但是,本指南没有提及有关刷新令牌的任何内容。

任何人都可以帮助我了解如何在 Java Spring Boot 中实现这一点吗? 或者有没有其他方法可以让用户保持登录状态?

如果配置正确,Spring 提供获取新访问令牌的功能,即如果authorizedGrantTypes包含"refresh_code"

您应该使用刷新令牌通过使用令牌端点来获取新的访问令牌,如下所示:

curl -H "Authorization: Bearer [base64encode(clientId:clientSecret)]" "https://yourdomain.com/oauth/token?grant_type=refresh_token&refresh_token=[yourRefreshToken]"

例子:

curl -X POST -H 'Authorization: Basic dGVzdGNsaWVudDpzZWNyZXQ=' -d 'refresh_token=fdb8fdbecf1d03ce5e6125c067733c0d51de209c&grant_type=refresh_token' localhost:3000/oauth/token

{
    "token_type":"bearer",
"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiVlx1MDAxNcKbwoNUwoonbFPCu8KhwrYiLCJpYXQiOjE0NDQyNjI4NjYsImV4cCI6MTQ0NDI2Mjg4Nn0.Dww7TC-d0teDAgsmKHw7bhF2THNichsE6rVJq9xu_2s",
"expires_in":20,
"refresh_token":"7fd15938c823cf58e78019bea2af142f9449696a"
}

如此处所述: https : //auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/

Ref - Spring Boot + Refresh Expired JWT 实现

一旦 JWT 过期,用户/系统将调用另一个 url 假设 /refreshtoken。 与此请求一起,还应传递过期的 JWT。 然后服务器将返回一个新的 JWT,用户/系统可以使用它。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM