Browser login with ZITADEL
Run the browser in AUTH_MODE=oidc with a configured Go API. For the local Projects demo, set AUTH_MODE=demo and leave the browser OIDC settings unset.
ZITADEL application
Create a confidential Web application in the development ZITADEL project. Configure Authorization Code with client authentication Basic. Register the exact redirect URI <APP_ORIGIN>/auth/callback. Use the same hostname to open the web app as in the registered URI. ZITADEL development mode may be needed to register a loopback HTTP URI.
Select the custom Login V2 experience for this OIDC client. Set its base URI to the application's public origin so the provider identifies the application login page. Provision a separate service account for the web server with the instance login-client role (IAM_LOGIN_CLIENT) and user-management permission in the single configured identity organization (ORG_USER_MANAGER). Store its expiring personal access token in the web service's secret store. Rotate it before expiry. Keep setup administrator tokens outside the running application.
The web server requests a code using S256 PKCE and validates the returned ID token against the issuer and its signing keys. Configure the application to issue JWT access tokens. The requested scope includes the API project as an audience and requests its project role assertion. Configure the API to expect the same issuer and project audience.
Web environment
| Setting | Value |
|---|---|
AUTH_MODE | oidc |
APP_ORIGIN | Canonical public origin without a trailing slash. Use HTTPS for deployed environments. Loopback HTTP, such as http://localhost:3000, is permitted for local development. |
OIDC_ISSUER | The HTTPS ZITADEL issuer URL from discovery. |
OIDC_CLIENT_ID | Confidential Web application ID. |
OIDC_CLIENT_SECRET | The application's Basic authentication secret. |
ZITADEL_ORG_ID | Decimal organization ID containing the browser users. |
ZITADEL_LOGIN_PAT | Private token for the dedicated login service account. Supply it only to the web server. |
OIDC_AUDIENCE | Decimal ZITADEL API project ID. |
DATABASE_URL | PostgreSQL connection URL for the web service. Apply the migrations before starting the web service. |
WEB_SESSION_KEY | A base64-encoded 32-byte key generated with openssl rand -base64 32. Share the same key across web replicas. |
GRAPHQL_URL | Trusted internal API endpoint, for example http://api:8080/graphql on a private network. The web service reads the profile at /me on this same API origin. |
Keep the client secret and session key in service secrets. Use a browser that accepts Secure cookies on the configured loopback origin or serve local HTTPS. The public origin must remain fixed behind a TLS-terminating proxy. Preserve the browser's Origin header on requests to the app and omit callback query strings from access logs.
Browser cookies carry opaque handles. PostgreSQL stores handle hashes and encrypts the access token with AES-256-GCM. Pending logins expire after 10 minutes. Sessions expire no later than the API token or eight hours after login. A new login removes expired rows. Sign-out clears the application session and any pending login. The web server attempts to terminate the associated provider session. A new login requires fresh authentication on the application domain even if provider cleanup was unavailable. Rotating the session key invalidates existing browser sessions.
Verify
From apps/web, run the tests with Node.js 24, OpenSSL, and a disposable PostgreSQL database.
npm ci
TEST_DATABASE_URL=postgres://postgres:local-test@127.0.0.1:5432/postgres npm run test:authThe test creates a random PostgreSQL schema and runs a local HTTPS OIDC fixture with a temporary certificate. On Linux, set TEST_WEB_IMAGE to a locally built web image to exercise the container entry point in the same test.
To verify against a development ZITADEL tenant, visit the configured origin, select Sign in, and complete authentication. The home page displays the stable application user ID returned by the API. With the Projects preset, open Projects, verify the expected access, then Sign out. Click Sign in again in the same browser and confirm fresh credentials are required. A direct visit to /projects should return to sign-in.