feat(web): OIDC sign-in and local dev identity provider (#39) #122

Merged
amiryahaya merged 8 commits from feat/39-oidc-login into main 2026-10-29 05:33:50 +01:00
Owner

Slice 2 of the ticket storefront (#39): sign-in and sign-out with OIDC authorization code + PKCE, built and tried against a local dev identity provider. Design docs/superpowers/specs/2026-10-29-storefront-login-design.md, plan docs/superpowers/plans/2026-10-29-storefront-login.md. No change under api/, no OpenAPI change, no migration.

What it does

  • Dev IdP: navikt/mock-oauth2-server 6.1.4 in deploy/compose.dev.yml, host port 8883 (bound to 127.0.0.1), issuer http://localhost:8883/default, access tokens get aud=kws-api. make up starts it. Users are typed at its login form (claims snippets in deploy/dev-idp/README.md); the mock has no user list.
  • Login in web/apps/ticket: oidc-client-ts (exact version), AuthProvider/useAuth, /auth/callback, header Sign in / name + Sign out, account name from GET /v1/me, bearer token on API calls. Token in memory only; PKCE state in sessionStorage during the redirect. Auth is off when VITE_OIDC_AUTHORITY is unset (production build, CI e2e): the public site is slice 1.
  • Return path only if same-site (//, schemes, backslashes, control characters, the callback path are refused), code exchanged once under StrictMode, callback URL cleaned from history, fixed error text only (no IdP text, tokens or codes shown or logged), sign-out drops the stored user first so the id token is not in the end-session URL, strict-origin referrer policy.
  • Phone header (320 px): brand on top, currency and account on one row below; unchanged when auth is off.
  • Local real-IdP journey pnpm --filter @kws/ticket e2e:idp (not in pnpm test or CI).

Verification

  • pnpm typecheck, pnpm test (142), pnpm build green; standard Playwright e2e in Playwright's image: 104 passed / 46 skipped by design.
  • Real-IdP journey against the real mock IdP and API: 3/3 (sign in and return to the same URL, bearer on /v1/me, nothing in localStorage/sessionStorage/URL, sign out, 320 px header signed in and out). Also shown in a headless browser round trip.
  • make cover: 91.3% (minimum 80%; Go code unchanged).
  • Reviews: whole-branch dual pass (complexity, then correctness), task review of the login code, scoped re-checks; no critical findings, all important ones fixed (id token in the logout URL, a test that could not fail).

Author calls (owner to check)

  • A page reload shows signed-out until Sign in is clicked (no silent renew yet). [verify]
  • Dev users are claims pasted at the mock form, not a picker. The mock accepts any client id and redirect URI, so it must never be deployed.
  • VITE_OIDC_SCOPE / VITE_OIDC_AUDIENCE were dropped (YAGNI); add them when Zitadel needs an audience scope.
  • reuseExistingServer is now false in playwright.config.ts, so a running pnpm dev (auth on) cannot leak into the standard e2e.

Not verified

  • Zitadel (a client_id-only end-session logout may show a confirm page); production CORS from the SPA to the IdP.
  • Real phones, Safari and Firefox (:has() is used in the phone header CSS).
  • A 401 on endpoints other than /v1/me (an expired token keeps the header showing the name until /v1/me refetches); the client-wide onResponse handler is deferred to #40.
  • The login journey is not in CI (no IdP service container); CI covers login with unit tests only.

Refs #39 (does not close it).

🤖 Generated with Claude Code

Slice 2 of the ticket storefront (#39): sign-in and sign-out with OIDC authorization code + PKCE, built and tried against a local dev identity provider. Design `docs/superpowers/specs/2026-10-29-storefront-login-design.md`, plan `docs/superpowers/plans/2026-10-29-storefront-login.md`. No change under `api/`, no OpenAPI change, no migration. ## What it does - **Dev IdP:** `navikt/mock-oauth2-server` 6.1.4 in `deploy/compose.dev.yml`, host port **8883** (bound to 127.0.0.1), issuer `http://localhost:8883/default`, access tokens get `aud=kws-api`. `make up` starts it. Users are typed at its login form (claims snippets in `deploy/dev-idp/README.md`); the mock has no user list. - **Login in `web/apps/ticket`:** `oidc-client-ts` (exact version), `AuthProvider`/`useAuth`, `/auth/callback`, header Sign in / name + Sign out, account name from `GET /v1/me`, bearer token on API calls. Token in memory only; PKCE state in `sessionStorage` during the redirect. **Auth is off when `VITE_OIDC_AUTHORITY` is unset** (production build, CI e2e): the public site is slice 1. - Return path only if same-site (`//`, schemes, backslashes, control characters, the callback path are refused), code exchanged once under StrictMode, callback URL cleaned from history, fixed error text only (no IdP text, tokens or codes shown or logged), sign-out drops the stored user first so the id token is not in the end-session URL, `strict-origin` referrer policy. - Phone header (320 px): brand on top, currency and account on one row below; unchanged when auth is off. - Local real-IdP journey `pnpm --filter @kws/ticket e2e:idp` (not in `pnpm test` or CI). ## Verification - `pnpm typecheck`, `pnpm test` (142), `pnpm build` green; standard Playwright e2e in Playwright's image: 104 passed / 46 skipped by design. - Real-IdP journey against the real mock IdP and API: 3/3 (sign in and return to the same URL, bearer on `/v1/me`, nothing in `localStorage`/`sessionStorage`/URL, sign out, 320 px header signed in and out). Also shown in a headless browser round trip. - `make cover`: **91.3%** (minimum 80%; Go code unchanged). - Reviews: whole-branch dual pass (complexity, then correctness), task review of the login code, scoped re-checks; no critical findings, all important ones fixed (id token in the logout URL, a test that could not fail). ## Author calls (owner to check) - A page reload shows signed-out until Sign in is clicked (no silent renew yet). **[verify]** - Dev users are claims pasted at the mock form, not a picker. The mock accepts any client id and redirect URI, so it must never be deployed. - `VITE_OIDC_SCOPE` / `VITE_OIDC_AUDIENCE` were dropped (YAGNI); add them when Zitadel needs an audience scope. - `reuseExistingServer` is now false in `playwright.config.ts`, so a running `pnpm dev` (auth on) cannot leak into the standard e2e. ## Not verified - Zitadel (a `client_id`-only end-session logout may show a confirm page); production CORS from the SPA to the IdP. - Real phones, Safari and Firefox (`:has()` is used in the phone header CSS). - A 401 on endpoints other than `/v1/me` (an expired token keeps the header showing the name until `/v1/me` refetches); the client-wide `onResponse` handler is deferred to #40. - The login journey is not in CI (no IdP service container); CI covers login with unit tests only. Refs #39 (does not close it). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
At 320 px the signed-in header put the currency select alone on the right and the
account on a third row. The tools now take their own left-aligned row, the name
gives way (ellipsis) and the Sign out label stays on one line. The local journey
asserts it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(web): keep the auth-off phone header as in slice 1; test the sign-out failure path (#39)
All checks were successful
ci / changes (pull_request) Successful in 32s
ci / api (pull_request) Has been skipped
ci / clients (pull_request) Has been skipped
ci / web (pull_request) Successful in 6m31s
ci / ci-gate (pull_request) Successful in 14s
da57ba03cd
The phone header rule moved the currency select onto its own row even with sign-in off.
It now applies only when a Sign in / Sign out button exists, and an e2e covers the
auth-off header. Also covers signOut when dropping the stored user fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!122
No description provided.