- Navigate to Google APIs Developer Console
- Open Credentials
- Click on
Create Credentials
andOAuth client ID
- Select Application type
Web Application
- Enter as Authorised redirect URI
auth.yourdomain.tld/auth/resp
- Copy and save
Client Id
andClient Secret
- e.g.
******.apps.googleusercontent.com
anduqE8NtQQZ_******
- e.g.
- Configure the environment variables to the following:
ISSUER=https://accounts.google.com CLIENT_ID=******.apps.googleusercontent.com CLIENT_SECRET=uqE8NtQQZ_****** AUTH_DOMAIN=auth.yourdomain.tld COOKIE_DOMAIN=yourdomain.tld
- Create the traefik forwardauth middleware (middlewares.forwardauth.toml):
http: middlewares: keycloak: forwardAuth: address: "http://traefik-forward-auth:4181" # Note: You need to use the internal DNS name (e.g. docker container name) trustForwardHeader: true authResponseHeaders: [ "X-Forwarded-User" ]
- Final docker-compose:
traefik: image: traefik:latest networks: - traefik volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - ./config:/etc/traefik ports: - 80:80 - 443:443 restart: always whoami: image: containous/whoami networks: - traefik labels: # Docker - traefik.enable=true # Routing - traefik.http.routers.whoami.rule=Host(`whoami.yourdomain.tld`) - traefik.http.routers.whoami.tls.certresolver=letsencrypt - traefik.http.routers.whoami.tls.domains[0].main=*.yourdomain.tld - traefik.http.routers.whoami.tls.domains[0].sans=yourdomain.tld - traefik.http.routers.whoami.entrypoints=https - traefik.http.routers.whoami.middlewares=keycloak@file # Healthcehck - traefik.http.services.whoami.loadbalancer.server.port=80 - traefik.http.services.whoami.loadbalancer.healthcheck.path=/ - traefik.http.services.whoami.loadbalancer.healthcheck.interval=5s - traefik.http.services.whoami.loadbalancer.healthcheck.timeout=3s restart: always traefik-forward-auth: image: stivik/oidc-forward-auth networks: - traefik environment: - ISSUER=https://accounts.google.com - CLIENT_ID=******.apps.googleusercontent.com - CLIENT_SECRET=uqE8NtQQZ_****** - AUTH_DOMAIN=auth.yourdomain.tld - COOKIE_DOMAIN=yourdomain.tld - LOG_LEVEL=debug labels: # Docker - traefik.enable=true # Routing - traefik.http.routers.keycloak-forward.rule=Host(`auth.yourdomain.tld`) - traefik.http.routers.keycloak-forward.tls.certresolver=letsencrypt - traefik.http.routers.keycloak-forward.tls.domains[0].main=*.yourdomain.tld - traefik.http.routers.keycloak-forward.tls.domains[0].sans=yourdomain.tld - traefik.http.routers.keycloak-forward.entrypoints=https - traefik.http.services.keycloak-forward.loadbalancer.server.port=4181 - traefik.http.routers.keycloak-forward.middlewares=keycloak@file # Note: The forwardauth handler itself requires the forwardauth middleware
- When you now browse to
whoami.yourdomain.tld
you will be redirected to the Google Auth and after a successfully authentication you will be redirected back to the application.