Skip to content

Instantly share code, notes, and snippets.

@rud
Created April 29, 2026 15:11
Show Gist options
  • Select an option

  • Save rud/263c30d8e056fc87d6e0b33e144e75ab to your computer and use it in GitHub Desktop.

Select an option

Save rud/263c30d8e056fc87d6e0b33e144e75ab to your computer and use it in GitHub Desktop.

Which Problems Are Solved

When a relying party initiates an OIDC authorization request with prompt=none and Zitadel has no usable session for the request, the Login V2 flow violates OpenID Connect Core 1.0 §3.1.2.6 (Authentication Error Response). Two distinct broken paths in apps/login/src/lib/server/flow-initiation.ts:

  • Sessions exist but none is valid for the auth request (e.g. the end-user explicitly signed out at Zitadel, leaving stale entries in the multi-session cookie): the handler returns NextResponse.json({ error: "No active session found" }, { status: 400 }). Because prompt=none is typically initiated by a top-level navigation, the browser renders this JSON response directly — the user sees an unstyled Zitadel page reading "No active session found" with no way back to the originating app.
  • No sessions at all: the handler falls through the outer if (authRequest && sessions.length) guard into the bottom branch, which redirects the user to /loginname and displays the interactive login UI — the exact behaviour prompt=none forbids.

In both cases, the relying party never receives the spec-mandated redirect to its redirect_uri carrying error=login_required, so silent re-auth flows dead-end at Zitadel and silent SSO across applications cannot recover gracefully.

How the Problems Are Solved

Replace both broken short-circuits with a createCallback call using the error callback kind, which already exists in the backend:

const { callbackUrl } = await createCallback({
  serviceConfig,
  req: create(CreateCallbackRequestSchema, {
    authRequestId: requestId.replace("oidc_", ""),
    callbackKind: {
      case: "error",
      value: create(AuthorizationErrorSchema, {
        error: ErrorReason.LOGIN_REQUIRED,
      }),
    },
  }),
});
return NextResponse.redirect(callbackUrl);

Concrete edits in apps/login/src/lib/server/flow-initiation.ts:

  1. Hoist the Prompt.NONE check above the outer if (authRequest && sessions.length) guard so that the no-sessions case is handled the same way as the no-valid-session case rather than falling through to interactive login.
  2. Inside the Prompt.NONE branch, replace noSessionResponse (the JSON 400) with the login_required callback redirect above. Both the "no selectedSession" and the "no cookie/token" early returns funnel through the same helper.

The Go backend already does the right thing: CreateCallback with the error case dispatches to failAuthRequest, which calls errorReasonToOIDC and builds a spec-compliant URL via oidc.CreateErrorCallbackURL (see internal/api/grpc/oidc/v2/oidc.go). This change is purely a frontend fix to actually use that path.

Additional Changes

  • New tests in apps/login/src/lib/server/flow-initiation.test.ts covering three prompt=none scenarios:
    • no sessions in the cookie at all,
    • sessions present but findValidSession returns none / the cookie lacks a token (post-logout),
    • a valid session is available (regression — must still produce the success callback redirect).
  • Each test asserts the response is a redirect (302) to a URL whose query string contains error=login_required, rather than a JSON 400 or a redirect to /loginname.

Additional Context

  • OpenID Connect Core 1.0 §3.1.2.6 — Authentication Error Response: https://openid.net/specs/openid-connect-core-1_0.html#AuthError
  • The proto schema at proto/zitadel/oidc/v2/authorization.proto documents AuthorizationError with an explicit reference to the spec section above, and defines ERROR_REASON_LOGIN_REQUIRED = 9. The CreateCallbackRequest.callback_kind oneof in proto/zitadel/oidc/v2/oidc_service.proto was designed for exactly this case.
  • Discussion #10469 — "How to Implement Silent Login in Second App With Zitadel Session Check": maintainers recommend prompt=none for cross-application silent re-auth. This PR makes that recommendation actually work when the Zitadel session is gone.
  • Discussion #3959 — clarifies that iframe-based silent check is intentionally unsupported (Zitadel sets X-Frame-Options: DENY) and that redirect/popup prompt=none is the supported path. This PR fixes that supported path.
  • Reproduction: configure any OIDC client, sign in via Login V2, then sign out at Zitadel, then have the client initiate a top-level navigation to /oauth/v2/authorize?...&prompt=none. Observe the unstyled "No active session found" page rather than a redirect back to redirect_uri with error=login_required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment