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

cunj1qz1  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(69)

我已经按照这个指南https://auth0.com/blog/implementing-jwt-authentication-on-spring-boot/在我的web应用程序中实现了访问令牌,它工作得很好。然而,这个指南没有提到任何关于刷新令牌的内容。
有没有人可以帮助我如何在Java Sping Boot 中实现这一点?或者有没有其他方法可以让用户登录?

6za6bjd0

6za6bjd01#

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/

相关问题