Header authentication lets a trusted upstream proxy (for example, oauth2-proxy, NGINXDocumentation Index
Fetch the complete documentation index at: https://docs.cake.ai/llms.txt
Use this file to discover all available pages before exploring further.
auth_request, or an Istio ext-authz filter) sign users in to Cake Agents by forwarding their identity in HTTP headers. When a request arrives without an existing session cookie, the server reads the configured headers, upserts the user, and creates a Better Auth session for the request.
Use this when your platform already terminates SSO at the edge and you want Cake Agents to inherit that identity without a second login.
How it works
On every request without an active session:- The server checks the configured JWT header. If present, it decodes the token (no signature verification; the upstream proxy is trusted) and reads the email and name claims.
- If the JWT is missing or does not contain the claims, the server falls back to the configured email and name headers.
- If an email is found, the server looks up the user by email. If no user exists, one is created with that email and name.
- The server creates a new Better Auth session and sets a signed session cookie on the response so subsequent requests reuse the cookie.
Interaction with cookie sessions
Header auth never overrides an existing Better Auth session. If a request already carries a valid session cookie, header auth is a no-op for that request.Configuration
Header auth is off by default. Configure it through the Helm chart’sheaderAuth values, which map to environment variables on the web deployment.
| Helm value | Environment variable | Default | Description |
|---|---|---|---|
headerAuth.enabled | CAKE_HEADER_AUTH_ENABLED | false | Enables the plugin. |
headerAuth.email.header | CAKE_HEADER_AUTH_EMAIL_HEADER | unset | Header that carries the user’s email when no JWT is present. |
headerAuth.email.claim | CAKE_HEADER_AUTH_EMAIL_CLAIM | email | JWT claim that contains the user’s email. |
headerAuth.jwt.header | CAKE_HEADER_AUTH_JWT_HEADER | unset | Header that carries an unsigned JWT with identity claims (decoded only). |
headerAuth.user.header | CAKE_HEADER_AUTH_USER | unset | Header that carries the user’s display name when no JWT is present. |
headerAuth.user.claim | CAKE_HEADER_AUTH_USER_CLAIM | name | JWT claim that contains the user’s display name. |
headerAuth.jwt.header or headerAuth.email.header for the plugin to do anything. If only the JWT header is set, the email and name come from JWT claims. If only plain headers are set, the JWT step is skipped.
If both a JWT and plain headers are present, JWT claims take precedence and plain headers are used as fallbacks for whichever field the JWT does not provide.
Example: oauth2-proxy in front of Cake Agents
Thisvalues.yaml snippet enables header auth and reads identity from headers that oauth2-proxy injects:
values.yaml
headerAuth.jwt.header at it and adjust the claim names if they differ from the defaults:
values.yaml
Notes
- Requests with internal Cake email addresses are rejected before a user is created. This is enforced by the internal email plugin, regardless of which header the email came from.
- The session created by header auth is a regular Better Auth session and is visible to
/api/auth/get-sessionand other Better Auth endpoints. - Header auth runs alongside SSO and the OAuth provider, so you can enable it together with
oidcfor users who hit the app directly.