I have a Java Spring backend that I've deployed onto ArgoCD with Kubernetes manifests. The backend is protected by having the user login into Keycloak. After it is deployed, I go to /api/application-info, and it then makes me log in to Keycloak. But after it I log in, it redirects me back and I just see This page isn’t working. If the problem continues, contact the site owner. HTTP ERROR 401.
Looking at the backend logs, I see 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". After googling, one page said that perhaps the client ID was wrong, but I double checked it and it was fine. I am setting the Keycloak client ID in the "application.yml" file, for example:
spring:
security:
oauth2:
client:
provider:
oidc:
issuer-uri: https://mykeycloak.com/auth/realms/myrealm
registration:
oidc:
client-id: myclientid
client-secret: myclientpw
Anyone know how else I can debug this?
Here is the Virtual Service. I know it is working because (1) I can go to /api and it will bring me to /api/, and (2) I go to /api/application-info, and it then makes me log in to 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