You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring 6 OAuth 2.0 PKCE公开客户端无法获取Refresh Token求助

问题:Spring Boot 3 OAuth2授权服务器公开客户端无法获取Refresh Token

我基于Spring 6 + Spring Boot 3搭建了OAuth 2.0授权服务器(AuthServer)和资源服务器(ResourceServer)。JS客户端可以正常完成登录流程,获取授权码后也能成功换取access_token,但返回的JSON响应中仅包含access_token、scope、id_token、token_type、expires_in字段,没有预期的refresh_token。这导致access_token(有效期300秒)过期后无法自动刷新,让用户每5分钟手动刷新浏览器显然不可行。

我已经尝试过以下操作:

  • 严格遵循官方指南配置,同时参考教程视频
  • 咨询AI获取配置建议
  • 在application.properties中添加了offline_access scope、refresh_token授权类型,并开启refresh token支持,具体配置如下:
spring.application.name=authorizationserver
server.port=8080

spring.security.oauth2.authorizationserver.client.client-1.registration.client-id=client
#spring.security.oauth2.authorizationserver.client.client-1.registration.client-secret={bcrypt}$2a$12$qew6z2l8LLQQeTRxqZekHOlT0jPtyrosuHtskyQBZiFOUaxXAgpIC
#spring.security.oauth2.authorizationserver.client.client-1.registration.client-authentication-methods=client_secret_basic
spring.security.oauth2.authorizationserver.client.client-1.registration.client-authentication-methods=none
spring.security.oauth2.authorizationserver.client.client-1.registration.authorization-grant-types=authorization_code,refresh_token
#spring.security.oauth2.authorizationserver.client.client-1.registration.redirect-uris=http://127.0.0.1:8082/login/oauth2/code/spring
spring.security.oauth2.authorizationserver.client.client-1.registration.redirect-uris=http://127.0.0.1:5173/callback

# not working wether with or without client.client-1
spring.security.oauth2.authorizationserver.client.client-1.token.refresh-token.enabled=true

spring.security.oauth2.authorizationserver.client.client-1.registration.scopes=user.read,user.write,openid,offline_access
spring.security.oauth2.authorizationserver.client.client-1.require-authorization-consent=true
logging.level.org.springframework.security=DEBUG

编辑补充
后续了解到PKCE公开客户端默认无法获取refresh token,目前只能通过定期将用户重定向到认证服务器,重新生成授权码来换取新的access_token,但这并非理想方案,希望能找到可行的解决办法。


内容的提问来源于stack exchange,提问作者Termo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 04:07:12