K8S 上的 Keycloak:无法使用用户名和密码对用户进行身份验证

Keyclaok on K8S: not able to authenticate a user with username and password

我正在将 Keycloak 与我的 springboot 服务集成,全部部署在 GKE 上,我按照 Keycloak 的安装说明进行操作,一切顺利,当我尝试使用 REST API 来验证已创建的用户时,使用以下 curl 请求:

curl --location --request POST 'http://<MY_KEYCLOAK_PUBLIC_IP>/auth/realms/demo/protocol/openid-connect/auth' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=demo-app' \
--data-urlencode 'username=test' \
--data-urlencode 'password=test' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_secret=ee39b325-7dw4-4c0c-681f-29e2f7f63f57'

我收到以下错误

{"timestamp":"2021-07-03T20:20:23.570+00:00","status":404,"error":"Not Found","message":"","path":"/"} 

知道本地部署的 keycloak 一切正常,我认为 redirect URL 有问题但不确定。

对于keycloak客户端配置,在下面找到:

编辑:

当我用 * 替换 Redirect URL 时,我得到了一个不同的错误:

{
    "error": "RESTEASY003210: Could not find resource for full path: http://<KEYCLOACK_IP>/auth/*?error=invalid_request&error_description=Missing+parameter%3A+response_type"
}

您正在尝试使用 Direct Access Grant,因此您必须 POST 数据到令牌端点(而不是授权端点):

curl -s -X POST \
  --data-urlencode "client_id=demo-app" \
  --data-urlencode "client_secret=ee39b325-7dw4-4c0c-681f-29e2f7f63f57" \
  --data-urlencode "username=test" \
  --data-urlencode "password=test" \
  --data-urlencode "grant_type=password" \
  http://<MY_KEYCLOAK_PUBLIC_IP>/auth/realms/demo/protocol/openid-connect/token