java - 如何在 Spring Boot 中实现刷新 token

标签 java spring-boot jwt token

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

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

最佳答案

如果配置正确,Spring 提供了获取新访问 token 的功能,即如果 authorizedGrantTypes 包含 “refresh_code”

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

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/

关于java - 如何在 Spring Boot 中实现刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49877427/

相关文章:

java - 我如何从另一个类获取字符串?

java - SSL 证书 - 不存在主题备用名称

java - Tomcat 始终创建新 session

jquery - 包括带有 Spring Boot 的 ES6 和 Webpack

spring-boot - Spring Boot 配置文件特定属性

java - 什么是堆栈图框

java - 在 spring data elasticsearch 中保存 ENUM

node.js - 如何使用 jwks-rsa 库获取 token 的 key child ( key ID)

java - JwtBuilder 添加\到我的 Json 字符串 - Java

c# - 如何使用 .NET Core 使用 UTC 时间验证 JWT