Skip to content

feat: realm-bind the authorize and token flow - #3194

Merged
tada5hi merged 1 commit into
masterfrom
feat/authorize-realm-binding
Jul 7, 2026
Merged

tada5hi merged 1 commit into
masterfrom
feat/authorize-realm-binding

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A downstream app lets the user pick a realm and redirects to /authorize with that realm's client. If the browser still carries an authup session for another realm (e.g. the user logged in to RealmA earlier and logged out only in the downstream app — authup-origin cookies are untouched), authup silently continued as the RealmA identity: because every realm's web client is built_in, the consent step auto-submitted, and the server performed no identity-realm ↔ client-realm check. The downstream app asked for RealmB and received RealmA tokens — a confused deputy whose artifact carried a RealmA iss/signing-key with a RealmB aud.

Fix

An identity may only authorize, redeem a code for, or refresh a token against a client in its own realm, enforced server-side at three independent points (the kit UI is UX only — the server is authoritative):

  1. POST /authorize issuance — OAuth2Authorization.authorize() throws login_required (OAUTH_LOGIN_REQUIRED, HTTP 400, no identity data in the body — no realm-enumeration oracle) when the identity realm ≠ the client realm.
  2. /token code redemption — the code verifier's new realmId option (fed client.realm_id) rejects code.realm_id != client.realm_id with invalid_grant. Covers identity-provider-callback codes and any in-flight pre-deploy codes.
  3. /token refresh parity — a public client refreshing a token whose realm differs from the client's realm → invalid_grant (kills legacy cross-realm web-client refresh tokens). Confidential clients stay exempt — the secret proves identity, and the documented cross-realm password grant relies on it.

Also included:

  • Realm-mismatch UI — the SSR /authorize page renders a "sign in to {realm}" / "return to application" card (the latter only when the redirect_uri matched a registered pattern) instead of auto-consenting, gated so a built_in client can't auto-consent before the store resolves the identity's realm.
  • Clickjacking guard — all SSR auth pages send Content-Security-Policy: frame-ancestors 'none' + X-Frame-Options: DENY.
  • Deterministic client resolution — a name-identified client at /authorize now requires a realm hint (invalid_request otherwise); every realm has a web client, so a bare name was ambiguous.

Testing

Full apps/server-core suite (1111 tests) green, plus @authup/i18n locale parity (77) and @authup/client-web-kit (11). New tests: scenario-1 reproduction (login_required) + same-realm control, the code-verifier realm branch, the refresh-parity reject + control, and the name-hint guard. Two pre-existing tests that minted codes via a cross-realm master-admin authorize were updated to authorize as a same-realm user (their fixture relied on the now-closed path).

Breaking change

Master-realm admins can no longer authorize into another realm's app via the built-in web client. Previously-issued cross-realm artifacts were malformed (RealmA iss/key + RealmB aud), so intentional reliance is implausible — use realm-local accounts.

Scope / follow-ups

This is PR A of the plan in .agents/plans/041-authorize-session-binding.md. It fully closes the cross-realm scenario. The account-switch UX (prompt=select_account + chooser) and cross-app logout via the standard end_session_endpoint are PRs B and C — the latter is the RP-agnostic mechanism that ends a lingering authup session on a downstream logout (kit and non-kit RPs alike), so this PR deliberately does not add a kit-specific session-delete to store.logout().

Summary by CodeRabbit

  • New Features

    • Added realm-aware sign-in handling, including a clearer “different realm” message and a way to switch accounts.
    • Auth screens now show the target realm and whether a redirect back to the app is safe.
  • Bug Fixes

    • Prevented authorization, code exchange, and refresh flows from crossing realm boundaries in unsupported cases.
    • Added stronger protection for server-rendered auth pages against being embedded in other sites.
  • Chores

    • Added new user-facing error messages and translations for multiple languages.

Copilot AI review requested due to automatic review settings July 7, 2026 14:22
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds server-side enforcement that an authenticated identity's realm must match the target client's realm across /authorize, code redemption, and public-client refresh flows. Introduces OAuth2LoginRequiredError, a client-side realm-mismatch UI, clickjacking headers on SSR pages, i18n strings, and supporting tests.

Changes

Realm Binding Enforcement

Layer / File(s) Summary
New login-required error type
packages/errors/src/constants.ts, packages/specs/src/oauth2/constants.ts, packages/specs/src/oauth2/error/login-required.ts, packages/specs/src/oauth2/error/index.ts
Adds OAUTH_LOGIN_REQUIRED/LOGIN_REQUIRED error codes and OAuth2LoginRequiredError with a realmMismatch() factory.
Server-side realm parity checks
apps/server-core/src/core/oauth2/authorization/code-request/verifier/*, apps/server-core/src/core/oauth2/authorization/code/verifier/*, apps/server-core/src/core/oauth2/authorization/module.ts, apps/server-core/src/adapters/http/adapters/oauth2/grant-types/authorize.ts, .../refresh_token.ts
Requires a realm hint for name-identified clients, binds authorization codes to realmId, enforces realm match in authorize, and rejects cross-realm refresh tokens for public clients.
Authorize controller and SSR page updates
apps/server-core/src/adapters/http/controllers/workflows/authorize/module.ts, apps/server-core/src/adapters/http/ui/render.ts, apps/server-core/ui/src/pages/authorize.vue
Passes realm and redirectUriVerified through to the SSR payload and adds Content-Security-Policy/X-Frame-Options headers.
Client-web-kit realm mismatch UI
packages/client-web-kit/src/components/workflows/authorize/*
Adds AuthorizeRealmMismatch component, wires realm props and switchAccount/loginRequired handling into Authorize.vue and AuthorizeForm.vue.
i18n translations
packages/i18n/src/catalogs/*/client.ts, packages/i18n/src/catalogs/*/error.ts, packages/i18n/src/constants.ts
Adds realm-mismatch and login-required translation keys/strings across de/en/es/fr catalogs.
Tests and architecture docs
apps/server-core/test/unit/**, .agents/architecture.md
Adds/updates unit tests for realm-hint requirement, code realm binding, cross-realm authorize/refresh behavior, and documents the plan 041 rules.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AuthorizeGrant as HTTPOAuth2AuthorizeGrant
  participant Authorization as OAuth2Authorization
  participant CodeVerifier as OAuth2AuthorizationCodeVerifier
  participant RefreshGrant as HTTPOAuth2RefreshTokenGrant

  Client->>AuthorizeGrant: POST /authorize
  AuthorizeGrant->>Authorization: authorize(data, identity)
  Authorization->>Authorization: compare data.realm_id vs identity.data.realm.id
  Authorization-->>AuthorizeGrant: OAuth2LoginRequiredError.realmMismatch() (on mismatch)
  Client->>AuthorizeGrant: POST /token (code redemption)
  AuthorizeGrant->>CodeVerifier: verify(code, realmId: client.realm_id)
  CodeVerifier-->>AuthorizeGrant: OAuth2GrantError.invalid() (on mismatch)
  Client->>RefreshGrant: POST /token (refresh)
  RefreshGrant->>RefreshGrant: compare payload.realm_id vs client.realm_id (public client only)
  RefreshGrant-->>Client: OAuth2GrantError.invalid() (on mismatch)
Loading
sequenceDiagram
  participant AuthorizeForm
  participant Authorize as Authorize.vue
  participant Store as Pinia store
  participant Mismatch as AuthorizeRealmMismatch

  AuthorizeForm->>AuthorizeForm: auto-consent fails with error=login_required
  AuthorizeForm-->>Authorize: emit loginRequired
  Authorize->>Store: switchAccount() calls store.logout()
  Authorize->>Authorize: compare codeRequest.realm_id vs realmId
  Authorize->>Mismatch: render with client/realm names, redirectUriVerified, onSwitch
  Mismatch-->>Store: emit switch -> switchAccount()
Loading

Possibly related PRs

  • authup/authup#3020: Both PRs extend OAuth2AuthorizationCodeVerifier's inputs/validation logic in the same authorization-code verifier files.
  • authup/authup#3104: Both PRs implement realm-scoped login/authorization flows using realm_id inputs enforced by the main PR's binding checks.
  • authup/authup#3177: Both PRs modify realm resolution/validation in the same HTTPOAuth2AuthorizeGrant/HTTPOAuth2RefreshTokenGrant handlers.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding realm binding to the authorize and token flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/authorize-realm-binding

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3194

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3194

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3194

@authup/access

npm i https://pkg.pr.new/@authup/access@3194

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3194

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3194

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3194

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3194

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3194

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3194

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3194

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3194

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3194

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3194

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3194

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3194

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3194

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3194

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3194

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3194

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3194

commit: 1747002

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR closes a cross-realm “confused deputy” gap by enforcing that an authenticated identity can only authorize/redeem/refresh tokens against clients in the same realm, with server-side checks as the source of truth and UI changes providing safe UX around realm mismatch.

Changes:

  • Add a login_required OAuth/OIDC error (ErrorCode.OAUTH_LOGIN_REQUIRED, OAuth2ErrorCode.LOGIN_REQUIRED) and translations.
  • Enforce realm-binding at three layers: /authorize issuance, /token code redemption, and /token refresh (public clients only), plus deterministic client resolution for name-identified clients.
  • Add SSR/kit UX and headers: realm-mismatch card + guarded “return to app”, and clickjacking protection headers on SSR workflow pages.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/specs/src/oauth2/error/login-required.ts Introduces OAuth2LoginRequiredError for login_required cases (incl. realm mismatch).
packages/specs/src/oauth2/error/index.ts Exports the new login-required error.
packages/specs/src/oauth2/constants.ts Adds OAuth2ErrorCode.LOGIN_REQUIRED.
packages/i18n/src/constants.ts Adds client-facing translation keys for realm-mismatch UI.
packages/i18n/src/catalogs/fr/error.ts Adds French translation for OAUTH_LOGIN_REQUIRED.
packages/i18n/src/catalogs/fr/client.ts Adds French realm-mismatch UI strings.
packages/i18n/src/catalogs/es/error.ts Adds Spanish translation for OAUTH_LOGIN_REQUIRED.
packages/i18n/src/catalogs/es/client.ts Adds Spanish realm-mismatch UI strings.
packages/i18n/src/catalogs/en/error.ts Adds English translation for OAUTH_LOGIN_REQUIRED.
packages/i18n/src/catalogs/en/client.ts Adds English realm-mismatch UI strings.
packages/i18n/src/catalogs/de/error.ts Adds German translation for OAUTH_LOGIN_REQUIRED.
packages/i18n/src/catalogs/de/client.ts Adds German realm-mismatch UI strings.
packages/errors/src/constants.ts Adds ErrorCode.OAUTH_LOGIN_REQUIRED.
packages/client-web-kit/src/components/workflows/authorize/AuthorizeRealmMismatch.vue New realm-mismatch card with safe “return to application” behavior.
packages/client-web-kit/src/components/workflows/authorize/AuthorizeForm.vue Emits loginRequired on server login_required during auto-consent.
packages/client-web-kit/src/components/workflows/authorize/Authorize.vue Gates built-in auto-consent on resolved identity realm; renders mismatch UI.
apps/server-core/ui/src/pages/authorize.vue Passes realm summary + redirect-uri verification into SSR authorize page payload.
apps/server-core/test/unit/http/controllers/workflows/token/grant-refresh-token.spec.ts Adds refresh-token realm-parity tests for public clients (reject/allow controls).
apps/server-core/test/unit/http/controllers/workflows/token/grant-authorize.spec.ts Adds realm-mismatch /authorize test + same-realm control; updates code issuance to use same-realm user.
apps/server-core/test/unit/core/oauth2/authorization/code/verifier/module.spec.ts Adds tests for verifier realmId option (match/mismatch/no-bound-realm).
apps/server-core/test/unit/core/oauth2/authorization/code-request/verifier/module.spec.ts Adds test for deterministic name+realm hint requirement and adjusts unknown-client test.
apps/server-core/src/core/oauth2/authorization/module.ts Enforces identity-realm == client-realm at authorization issuance (login_required).
apps/server-core/src/core/oauth2/authorization/code/verifier/types.ts Adds realmId option to code verification.
apps/server-core/src/core/oauth2/authorization/code/verifier/module.ts Enforces code realm parity during redemption (defense in depth).
apps/server-core/src/core/oauth2/authorization/code-request/verifier/types.ts Extends verifier result with redirectUriVerified.
apps/server-core/src/core/oauth2/authorization/code-request/verifier/module.ts Requires realm hint for name-identified clients; stamps data.realm_id; computes redirectUriVerified.
apps/server-core/src/adapters/http/ui/render.ts Adds clickjacking protection headers for SSR workflow pages.
apps/server-core/src/adapters/http/controllers/workflows/authorize/module.ts Adds realm summary + redirectUriVerified to SSR payload.
apps/server-core/src/adapters/http/adapters/oauth2/grant-types/refresh_token.ts Rejects cross-realm refresh for public clients (invalid_grant).
apps/server-core/src/adapters/http/adapters/oauth2/grant-types/authorize.ts Passes realmId into code verifier during code redemption.
.agents/architecture.md Documents plan 041 realm-binding design and enforcement points.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/server-core/src/core/oauth2/authorization/code-request/verifier/module.ts (1)

105-115: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redirect-URI check condition duplicated instead of reusing the new flag.

redirectUriVerified (line 108) computes the same boolean already re-checked on line 109 (if (client.redirect_uri && data.redirect_uri)). Reusing the variable avoids re-evaluating the same condition twice.

♻️ Proposed simplification
         const redirectUriVerified = !!(client.redirect_uri && data.redirect_uri);
-        if (client.redirect_uri && data.redirect_uri) {
+        if (redirectUriVerified) {
             const redirectUris = client.redirect_uri.split(',');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/server-core/src/core/oauth2/authorization/code-request/verifier/module.ts`
around lines 105 - 115, In the authorization code verifier module, the
redirect-URI presence check is duplicated in the same block. Reuse the existing
redirectUriVerified flag instead of repeating the client.redirect_uri &&
data.redirect_uri condition, and keep the isSimpleMatch /
OAuth2GrantError.redirectUriMismatch logic inside that single guarded branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@apps/server-core/src/core/oauth2/authorization/code-request/verifier/module.ts`:
- Around line 105-115: In the authorization code verifier module, the
redirect-URI presence check is duplicated in the same block. Reuse the existing
redirectUriVerified flag instead of repeating the client.redirect_uri &&
data.redirect_uri condition, and keep the isSimpleMatch /
OAuth2GrantError.redirectUriMismatch logic inside that single guarded branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e2dc9c4-d0ba-4559-8e05-1508654b9898

📥 Commits

Reviewing files that changed from the base of the PR and between 2fb862b and 1747002.

📒 Files selected for processing (31)
  • .agents/architecture.md
  • apps/server-core/src/adapters/http/adapters/oauth2/grant-types/authorize.ts
  • apps/server-core/src/adapters/http/adapters/oauth2/grant-types/refresh_token.ts
  • apps/server-core/src/adapters/http/controllers/workflows/authorize/module.ts
  • apps/server-core/src/adapters/http/ui/render.ts
  • apps/server-core/src/core/oauth2/authorization/code-request/verifier/module.ts
  • apps/server-core/src/core/oauth2/authorization/code-request/verifier/types.ts
  • apps/server-core/src/core/oauth2/authorization/code/verifier/module.ts
  • apps/server-core/src/core/oauth2/authorization/code/verifier/types.ts
  • apps/server-core/src/core/oauth2/authorization/module.ts
  • apps/server-core/test/unit/core/oauth2/authorization/code-request/verifier/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/code/verifier/module.spec.ts
  • apps/server-core/test/unit/http/controllers/workflows/token/grant-authorize.spec.ts
  • apps/server-core/test/unit/http/controllers/workflows/token/grant-refresh-token.spec.ts
  • apps/server-core/ui/src/pages/authorize.vue
  • packages/client-web-kit/src/components/workflows/authorize/Authorize.vue
  • packages/client-web-kit/src/components/workflows/authorize/AuthorizeForm.vue
  • packages/client-web-kit/src/components/workflows/authorize/AuthorizeRealmMismatch.vue
  • packages/errors/src/constants.ts
  • packages/i18n/src/catalogs/de/client.ts
  • packages/i18n/src/catalogs/de/error.ts
  • packages/i18n/src/catalogs/en/client.ts
  • packages/i18n/src/catalogs/en/error.ts
  • packages/i18n/src/catalogs/es/client.ts
  • packages/i18n/src/catalogs/es/error.ts
  • packages/i18n/src/catalogs/fr/client.ts
  • packages/i18n/src/catalogs/fr/error.ts
  • packages/i18n/src/constants.ts
  • packages/specs/src/oauth2/constants.ts
  • packages/specs/src/oauth2/error/index.ts
  • packages/specs/src/oauth2/error/login-required.ts

@tada5hi

tada5hi commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai pause

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

Reject cross-realm authorization: an identity may only authorize, redeem a
code for, or refresh a token against a client in its own realm. Previously a
lingering session for realm A, redirected to /authorize for realm B's client
(a downstream app's realm picker), silently minted realm-A tokens against
realm B's client — a confused deputy whose artifact carried realm-A
iss/signing-key with a realm-B aud.

Enforced server-side at three points (the kit realm-mismatch card is UX only):
- POST /authorize throws login_required (OAUTH_LOGIN_REQUIRED, HTTP 400, with
  no identity data in the body) when the identity realm != the client realm.
- /token code redemption rejects code.realm_id != client.realm_id with
  invalid_grant (covers identity-provider-issued and in-flight codes).
- /token refresh rejects a public client refreshing a foreign-realm token
  (confidential clients stay exempt for the cross-realm password grant).

Additionally: a name-identified client at /authorize now requires a realm hint
(invalid_request otherwise; every realm has a web client, so a bare name is
ambiguous), all SSR auth pages send frame-ancestors 'none' + X-Frame-Options:
DENY, and the authorize page renders a realm-mismatch card ("sign in to
{realm}" / "return to application", the latter only when the redirect_uri
matched a registered pattern) instead of silently auto-consenting.

BREAKING CHANGE: master-realm admins can no longer authorize into another
realm's app via the built-in web client (login_required at /authorize,
invalid_grant at /token). Previously-issued cross-realm artifacts were
malformed, so intentional reliance is implausible; use realm-local accounts.
@tada5hi
tada5hi force-pushed the feat/authorize-realm-binding branch from 1747002 to 5e10923 Compare July 7, 2026 14:41
@tada5hi
tada5hi merged commit b7fc25c into master Jul 7, 2026
4 checks passed
@tada5hi
tada5hi deleted the feat/authorize-realm-binding branch July 7, 2026 14:41
@github-actions github-actions Bot mentioned this pull request Jul 7, 2026
tada5hi added a commit that referenced this pull request Jul 8, 2026
…-ups) (#3197)

* fix: rp-initiated logout & authorize hardening (plan 041 audit follow-ups)

Post-merge fixes for defects and test gaps surfaced by an audit of plan 041
(#3194/#3195/#3196). Closes plan 042 items #1, #11 and most of #12.

Security / correctness:
- AEndSessionForm gates its on-mount local sign-out on
  `serverRevoked && hintSub === store.user.id` — a cross-site
  /logout?id_token_hint=<attacker's own token> can no longer force-log-out an
  unrelated victim who merely renders the page (forced-logout CSRF). The
  controller forwards `hintSub` (verified hints only) into the payload.
- LogoutController bounces back to the RP only when the logout was actually
  performed (serverRevoked && validated redirect). A hint-less or forged
  request renders the click-gated confirm page and redirects after sign-out,
  instead of 302-ing back while the session survives.
- Authorize.vue: a fresh login no longer re-prompts prompt=select_account
  (LoginForm `done` sets accountConfirmed), and the chooser waits for `user`
  to resolve (no empty-name flash).
- /authorize hydration payload trimmed to a ClientSummary DTO (no redirect_uri
  patterns, grant_types, internal URLs, secret flags).
- prompt=none removed from discovery prompt_values_supported + docs (its
  silent-auth error redirect is unimplemented).
- empty `max_age=` is treated as absent instead of coercing to 0
  (z.coerce.number('') === 0 would force re-authentication).
- AuthorizeForm renders a "Signed in as X - Not you?" switch chip (+ i18n).
- Remove the dead OAuth2AuthorizationCode.auth_time field; use specs enums for
  prompt/error string comparisons instead of literals.

Tests:
- /logout HTTP e2e matrix (revoke, redirect+state, hint-less no-op,
  access-token/forged hint no-revoke, unregistered redirect dropped).
- server-kit ignoreExpiry (expired+valid-sig accepted; bad-sig/nbf rejected).
- auth_time passthrough + auth_time!=refreshed_at pins; redirectUriVerified;
  confidential refresh exemption; cross-realm login_required no-identity-oracle
  body; clickjacking headers + trimmed-DTO; max_age empty-vs-0; kit gate spec.

* fix: use a button for the "Not you?" switch affordance

The account-switch affordance is an action, not navigation — render it as a
<button type="button"> styled like a link instead of an <a href="#"> so it has
correct button semantics and keyboard behavior (Enter/Space activation), and
matches the rest of the form's actions.

* fix: reliably skip the account chooser after a fresh login on /authorize

The prompt=select_account chooser reappeared right after entering
username/password on the hosted /authorize page. The previous fix keyed off
LoginForm's `done` emit, but on login the access-token flip re-renders
Authorize and unmounts LoginForm before `done` fires, so the flag that skips
the chooser was never set — the chooser stayed.

Key off the store's LOGGED_IN dispatcher event instead. It is emitted only by
an explicit login() (the form), never by a session restored from cookies
(resolve() → RESOLVED), so a lingering session still gets the chooser while a
fresh login skips it — independent of component mount/unmount timing.

Adds a component spec pinning all three cases (lingering shows, LOGGED_IN
skips, RESOLVED does not suppress).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants