【问题标题】:"Didn't find publicKey for specified kid" error occurs when deploy spring boot to tomcat将spring boot部署到tomcat时出现“没有找到指定孩子的publicKey”错误
【发布时间】:2020-05-15 19:55:06
【问题描述】:

我正在使用 Keycloak 来保护我的 rest api

我在 Keycloak 中有 2 个客户:

-我的前端:React 应用

-我的后端:Spring boot(仅承载类型)

当我运行 spring boot 应用程序时一切正常。 但我收到错误 401“没有找到指定孩子的公钥” 当我在tomcat中运行它时。 下面的一些配置:

keycloak.json

{
  "realm": "pet",
  "bearer-only": true,
  "auth-server-url": "http://localhost:8080/auth",
  "ssl-required": "none",
  "resource": "secure-api",
  "confidential-port": 0,
  "enable-cors" : true,
  "cors-max-age" : 1000,
  "cors-allowed-methods" : "POST, PUT, DELETE, GET",
  "cors-exposed-headers" : "WWW-Authenticate, My-custom-exposed-Header"
}

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <module-name>myapp</module-name>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Authors</web-resource-name>
            <url-pattern>/management/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>user</role-name>
        </auth-constraint>
    </security-constraint>

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>pet</realm-name>
    </login-config>

    <security-role>
        <role-name>admin</role-name>
    </security-role>
    <security-role>
        <role-name>user</role-name>
    </security-role>
</web-app>

context.xml

<Context path="/myapp">
    <Valve className="org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve"/>
</Context>

keycloak-7.0 和 tomcat-8

你有什么想法吗?

【问题讨论】:

    标签: tomcat keycloak


    【解决方案1】:

    终于找到了解决办法。

    注意您在 KC 管理仪表板中配置的默认签名算法令牌:

    HS256 需要 http://{domain}:8080/auth/realms/{realm-name}/.well-known/openid-configuration 中的公钥,不幸的是不知何故它不存在。然后出现“没有找到指定孩子的公钥”错误

    仅供参考:RS256 vs HS256: What's the difference?

    如果您使用 HS256,请确保 OIDC 元数据端点中的公钥

    使用其他算法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-04
      • 2018-06-21
      • 1970-01-01
      • 2020-06-17
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多