【问题标题】:Spring Security oAuth complains about missing JWT verifier key even though it's definedSpring Security oAuth 抱怨缺少 JWT 验证器密钥,即使它已定义
【发布时间】:2019-05-04 04:02:58
【问题描述】:

我正在将应用程序从 Spring Boot 1.5 迁移到 Spring Boot 2。这需要更新项目使用的 oAuth2 库,因为从 Spring Boot 2 开始,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 Boot 1.5.x 之前,此配置运行良好,但在升级到 Spring Boot 2(并移至 spring-security-oauth2-autoconfigure 库)后,我开始遇到此问题。

我可以通过访问上面配置中定义为keyUri: ${uaa.url}/oauth/token_key 的 URL 来访问浏览器中的密钥,因此它显然是一个有效的 URL。这可能是什么问题?

编辑:我在几个地方在网上找到的解决方案之一是添加一个虚拟 userInfoUri 值,如下所示:

security:
  oauth2:
    resource:
      userInfoUri: BUGFIX

我试过了,还是一样的错误。

【问题讨论】:

  • 看起来这可能是一个错误,解决方法可能是在您的 .yml 文件中添加一个无意义的userInfoUrigithub.com/spring-projects/spring-boot/issues/8565
  • @EdwinDiaz-Mendez 谢谢,我也试过了,没用。
  • 好的。对您的问题是您如何使用 .配置 .yml 文件的属性文件?是为了避免源头控制吗?另外你确定那里没有冲突吗?
  • 另外,请将keyUri 更改为key-uri,如果有帮助请告诉我。
  • @EdwinDiaz-Mendez 谢谢,我也试过了,没用。我认为key-uri 格式只有在你有一个 .properties 文件的情况下才会被遵循。我使用的是 .yml 文件,它需要 keyUri 格式。

标签: java spring spring-boot oauth-2.0


【解决方案1】:
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。

【讨论】:

  • 它看起来像 userInoUri 中的拼写错误。不应该是userInfoUri吗?
  • @amra 这确实是一个错字,编辑了答案。谢谢!
【解决方案2】:
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 文件中为我解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2019-05-20
    • 2014-09-17
    • 2023-03-24
    • 2015-10-31
    相关资源
    最近更新 更多