我正在将一个应用程序从Spring Boot1.5迁移到Spring Boot2。这需要更新项目使用的oAuth2库,因为从Spring Boot2开始,spring-security-oauth2库已经被spring-security-oauth2-autoconfigure取代(据我所知)。
无论哪种方式,在启动期间,我的项目都会抱怨缺少JWT验证器密钥( oAuth2所需的),尽管我清楚地拥有在application.yml文件中定义的密钥的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 Boot1.5.x之前,这种配置工作得很好,但是在升级到Spring Boot2(并转移到spring-security-oauth2-autoconfigure库)之后,我开始遇到这个问题。
我可以通过访问上面配置中定义为keyUri: ${uaa.url}/oauth/token_key的URL来访问浏览器中的密钥,因此它显然是一个有效的URL。这里会有什么问题呢?
编辑:我在网上找到的一个解决方案是添加一个虚拟的userInfoUri值,如下所示:
security:
oauth2:
resource:
userInfoUri: BUGFIX我尝试这样做,仍然得到相同的错误。
发布于 2019-04-29 08:12:43
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文件中为我做了这件事。
发布于 2020-02-12 20:02:24
spring:
security:
oauth2:
client:
clientId: xxxxxxxxxxxxxxxxxxxx
clientSecret: xxxxxxxxxxxxxxxxxxxxxxxx
accessTokenUri: https:graph.facebook.com/oauth/access_token
userAuthorizationUri: https://www.facebook.com/dialog/oauth
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
scope: profile email
resource:
userInfoUri: https://graph.facebook.com/me我在我的application.yml中使用了它,它终于可以工作了。你只需要用spring:对其进行子级处理(这对我来说很有效)。
此外,我认为您应该使用spring-boot-starter-oauth2-client。
https://stackoverflow.com/questions/53583955
复制相似问题