我有一个 Java Spring 后端,我已经使用 Kubernetes 清单部署到 ArgoCD 上。通过让用户登录 Keycloak 来保护后端。部署后,我转到 /api/application-info,然后它让我登录到 Keycloak。但是在我登录后,它会将我重定向回来,我只看到This page isn’t working. If the problem continues, contact the site owner. HTTP ERROR 401
.
查看后端日志,我看到了Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: The required audience is missing", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"
. 谷歌搜索后,一页说可能是客户 ID 错误,但我仔细检查了它并没有问题。我在“application.yml”文件中设置 Keycloak 客户端 ID,例如:
spring:
security:
oauth2:
client:
provider:
oidc:
issuer-uri: https://mykeycloak.com/auth/realms/myrealm
registration:
oidc:
client-id: myclientid
client-secret: myclientpw
任何人都知道我还能如何调试这个?
这是虚拟服务。我知道它正在工作,因为 (1) 我可以转到 /api,它会将我带到 /api/,并且 (2) 我转到 /api/application-info,然后它让我登录到 Keycloak。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ingress
spec:
hosts:
- myhost.io
gateways:
- public-gateway.istio-system.svc.cluster.local
http:
- match:
- uri:
exact: /api
redirect:
uri: /api/
- match:
- uri:
prefix: /api/
rewrite:
uri: /api/
route:
- destination:
host: mysite-be
port:
number: 80
websocketUpgrade: true
- match:
- uri:
prefix: /
route:
- destination:
host: mysite-fe
port:
number: 80