Google SSO
When Google OAuth credentials are configured, users can visit /auth/login, sign in with their Google account, and receive an API key — no admin intervention needed.
1. Create a Google OAuth client
Section titled “1. Create a Google OAuth client”- Go to Google Cloud Console → Credentials
- Click Create Credentials → OAuth 2.0 Client ID
- Application type: Web application
- Add Authorised redirect URI:
https://proxy.internal/auth/callback - Copy the Client ID and Client secret
2. Configure the proxy
Section titled “2. Configure the proxy”Environment variables:
GOOGLE_CLIENT_ID=123456789-abc.apps.googleusercontent.comGOOGLE_CLIENT_SECRET=GOCSPX-...AUTH_BASE_URL=https://proxy.internalHelm:
secrets: googleClientId: "123456789-abc.apps.googleusercontent.com" googleClientSecret: "GOCSPX-..." authBaseUrl: "https://proxy.internal"3. Verify
Section titled “3. Verify”Visit https://proxy.internal/auth/login. You should be redirected to Google’s consent screen.
User flow
Section titled “User flow”User → GET /auth/login → 302 to accounts.google.com/o/oauth2/auth → (user signs in and approves) → 302 to /auth/callback?code=...&state=... → proxy verifies HMAC state, exchanges code for token → fetches user profile (name, email) from Google → upserts user in database (create on first login, update on subsequent) → creates API key named "sso" → returns HTML page showing the keyState parameter security
Section titled “State parameter security”The state parameter is a HMAC-SHA256 signed nonce:
state = nonce + "." + HMAC-SHA256(secret, nonce)[:16]This is stateless — no server-side session storage is required. It works correctly with multiple uvicorn workers and multiple Kubernetes replicas. The PROXY_MASTER_KEY is used as the HMAC secret.
Key management
Section titled “Key management”- Each login creates a new key named
sso— it does not replace the previous one - Old keys remain valid unless deleted via the admin API
- The key is displayed once in the callback HTML page — users should save it immediately
Disabling
Section titled “Disabling”OAuth is disabled automatically when GOOGLE_CLIENT_ID is empty. The /auth/login endpoint returns 404.
Restricting to a specific domain
Section titled “Restricting to a specific domain”The current implementation does not restrict logins by email domain — any Google account can obtain a key. To restrict access:
- Set
GOOGLE_CLIENT_IDonly internally and do not publicly advertise/auth/login - Or add domain validation to
app/api/auth.pyafter fetching the user profile:
if not userinfo["email"].endswith("@yourcompany.com"): raise HTTPException(status_code=403, detail="Unauthorized domain")