java - Spring Security oAuth 提示缺少 JWT 验证程序 key ,即使它已定义

标签 java spring spring-boot oauth-2.0

我正在将应用程序从 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/

相关文章:

java - mysql.jdbc.driver类未找到异常

java - 使 Spring/Tomcat 与 HTML5 pushState 兼容

java - Camel + Groovy + Spring DSL 的奇怪行为

java - 使用ehcache来处理文件处理

java - 接受多部分文件的 DELETE 方法的 Mockmvc

java - Spring-Boot 使用依赖 jar 中的 JSP

java - 我想以编程方式获取 Android 中的应用程序崩溃信息,而不使用第 3 方应用程序或 bugsense 等 jars

Java HashMap 存储不同的对象

java - 在 Java 中区分关闭比 Runtime.setShutdownHook()

java - 我应该在哪里运行自定义 SQL 以在 Spring Boot 中的数据库中创建枚举类型?