我正在将应用程序从 Spring Boot 1.5 迁移到 Spring Boot 2。这需要更新项目使用的 oAuth2 库,因为从 Spring Boot 2 开始,spring-security-oauth2
库已已替换为 spring-security-oauth2-autoconfigure (根据我的理解)。
无论哪种方式,在启动过程中,我的项目都会提示 JWT validator key (oAuth2 所需的)丢失,即使我清楚地在我的 application.yml
文件中定义了该 key 的 URI,与其他oAuth2配置,如下:
security:
oauth2:
client:
userAuthorizationUri: ${uaa.url}/oauth/authorize
accessTokenUri: ${uaa.url}/oauth/token
clientId: ${security.oauth2.client.client-id}
clientSecret: ${security.oauth2.client.client-secret}
resource:
jwt:
keyUri: ${uaa.url}/oauth/token_key
我在启动过程中遇到的错误是:
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties@468bb799 failed:
Property: resourceServerProperties.tokenInfoUri
Value: null
Reason: Missing tokenInfoUri and userInfoUri and there is no JWT verifier key
在我使用 Spring Boot 1.5.x 之前,此配置工作得很好,但是在升级到 Spring Boot 2(并移动到 spring-security-oauth2-autoconfigure 库)之后,我开始得到这个问题。
我可以通过访问上面配置中定义为 keyUri: ${uaa.url}/oauth/token_key
的 URL 来访问浏览器中的 key ,因此它显然是一个有效的 URL。这里可能出现什么问题?
编辑:我在几个地方在网上找到的解决方案之一是添加一个虚拟的 userInfoUri 值,如下所示:
security:
oauth2:
resource:
userInfoUri: BUGFIX
我尝试了这个,仍然遇到同样的错误。
最佳答案
security:
oauth2:
client:
clientId: xxxx
clientSecret: xxxx
accessTokenUri: https://www/yyy.com/.well-known/oauth-authorization-server
userAuthorizationUri: https://www/yyy.com/.well-known/oauth-authorization-server
scope: openid profile email
resource:
userInfoUri: https://www/yyy.com/.well-known/oauth-authorization-server
sso:
loginpath: /authorization-code/callback
在 application.yaml 文件中为我解决了这个问题。
关于java - Spring Security oAuth 提示缺少 JWT 验证程序 key ,即使它已定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53583955/