我正在使用 Keycloak 来保护我的其余 api
我在 Keycloak 中有 2 个客户:
-我的前端:React 应用程序
-我的后端:Spring boot(仅承载类型)
当我运行 Spring Boot 应用程序时,一切正常。但是当我在tomcat中运行它时,出现错误401“没有找到指定孩子的公钥”。下面的一些配置:
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"
}
Run Code Online (Sandbox Code Playgroud)
网络.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>
Run Code Online (Sandbox Code Playgroud)
上下文.xml
<Context path="/myapp">
<Valve className="org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve"/>
</Context>
Run Code Online (Sandbox Code Playgroud)
keycloak-7.0 和 tomcat-8
你有什么主意吗?
最后,我找到了解决方案。
\n\n请注意 KC 管理仪表板中配置的默认签名算法令牌:
\n\n\n\nHS256 需要 http://{domain}:8080/auth/realms/{realm-name}/.well-known/openid-configuration 中的公钥,不幸的是它不在那里。然后出现 \xe2\x80\x9cDidn\t find publicKey for指定孩子\xe2\x80\x9d 错误
\n\n仅供参考:RS256 与 HS256:有什么区别?
\n\n如果您使用 HS256,请确保 OIDC 元数据端点中的公钥
\n\n或使用其他算法
\n| 归档时间: |
|
| 查看次数: |
4759 次 |
| 最近记录: |