Skip to content

feat(hub): add web sign-in for allowlisted browser apps - #18

Merged
5aaee9 merged 2 commits into
mainfrom
feat/hub-web-sign-in
Nov 27, 2026
Merged

5aaee9 merged 2 commits into
mainfrom
feat/hub-web-sign-in

Conversation

@5aaee9

@5aaee9 5aaee9 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Browser apps served from a PANDAR_CORS_ALLOWED_ORIGINS origin (for example the Ares slicer web app) can now sign users in to a Hub and get a tenant token. The flow mirrors the Android mobile login-ticket flow. Plugin and mobile behaviour is unchanged.

Contract

  1. Page GET /web-sign-in?redirect_url=<url>&code_challenge=<S256 base64url>&state=<opaque>
    • Same auth requirement, tenant selection, and ticket form as /mobile-sign-in, with en and zh strings.
    • There is no default redirect_url. If it is missing, the page shows an error state and makes no Hub call.
    • On submit, the createWebTicket server action calls the Hub. It then redirects to redirect_url with ticket, redirect_url, and state appended.
  2. Create POST /api/v1/tenants/{tenant_id}/web/login-tickets
    • Body {redirect_url, code_challenge}. Returns 201 {ticket, expires_at, redirect_url}.
    • Authorization and invalid_code_challenge validation are the same as the mobile route.
    • Adds LoginTicketKind::Web (stored kind "web"). Tickets use the prefix pandar_web_ticket_.
  3. Callback validation
    • The scheme must be http or https, with no userinfo, no query (including a bare ?), and no fragment.
    • The URL origin (Url::origin().ascii_serialization(), which matches the browser Origin header) must exactly equal an allowlist entry. Any path is allowed.
    • An empty or unset allowlist rejects every callback.
    • A rejected callback returns 400 invalid_redirect_url.
  4. Exchange POST /api/v1/web/login-tickets/exchange
    • Body {ticket, code_verifier}. Returns 200 {token, expires_at, profile:{user_id,user_name,tenant_id,tenant_name}}. user_name is the display name of the user who created the ticket, not the token name.
    • Tickets are one-use, expire, and need a matching PKCE S256 verifier. Any failure returns 401 {"error":"invalid_plugin_ticket"}.
    • The route is mounted in the CORS-scoped client router, so preflight and response headers work from allowlisted origins.
  5. Token
    • The issued token has scope web:session (TenantTokenScope::WebSession), prefix pandar_web_, name "Ares web", and a 30-day TTL.
    • web:session is special-cased everywhere mobile:session is, through the new TenantTokenScope::is_user_session(). That covers session-user resolution, tenant_token_allows_role, and the rule that blocks manual token creation (invalid_scope).
    • Audit events are web_login_ticket.create and web_login_ticket.exchange, with actor scope web:session.
    • The printer-events WebSocket has no Origin check. A test confirms an upgrade sent with an allowlisted Origin header connects.
  6. Contract
    • contracts/hub-client.openapi.json adds both paths and the schemas WebLoginTicketRequest, WebTicketExchangeRequest, and WebTicketExchangeResponse. The TypeScript clients were regenerated. Kotlin is unchanged because these schemas are not Kotlin roots.
    • The contract types tenant-token scopes as plain strings with no enum, so the new scope needed no contract change.

Test plan

  • routes::tests::web_sign_in covers:
    • callbacks accepted on allowlisted origins
    • callbacks rejected for an unlisted origin, wrong scheme, wrong port, query, empty query, fragment, userinfo, a non-http scheme, a relative URL, and an empty allowlist
    • the PKCE challenge being required
    • one-use exchange, a PKCE verifier mismatch, and a cross-kind exchange through the mobile route
    • the issued token's scope (web:session) and owner
    • printer listing and job upload with a web session, and role downgrade
    • the ACAO header on an exchange from the allowlisted origin
    • the printer-events ticket and WebSocket upgrade with an Origin header
  • The CORS preflight test also covers /api/v1/web/login-tickets/exchange. The manual-scope rejection test and the OpenAPI route test include the new routes.
  • app/web-sign-in/page.test.tsx covers the missing-callback state, callback handoff for a single tenant and across tenant selection, and the form's hidden fields. actions.test.ts covers createWebTicket for the redirect URL and for a Hub rejection.
  • cargo clippy --workspace --all-targets is clean, and nix fmt made no changes. The pandar-quality module-size check passes.
  • cargo nextest run --workspace: all 1298 tests outside pandar-network-plugin pass. The pandar-network-plugin Studio contract tests fail locally only because reference/BambuStudio is not checked out.
  • npm run test:web (263 passed), npm run typecheck:web, npm --prefix frontend run lint, and npm run check:hub-clients pass.

🤖 Generated with Claude Code

Browser apps on a PANDAR_CORS_ALLOWED_ORIGINS origin, such as the Ares
slicer web app, need a tenant token without a native callback scheme.
This mirrors the Android ticket flow:

- /web-sign-in?redirect_url=&code_challenge=&state= reuses the mobile
  tenant selection and redirects to the callback with ticket,
  redirect_url, and state. A missing redirect_url shows an error state.
- POST /api/v1/tenants/{tenant_id}/web/login-tickets accepts only http(s)
  callbacks without userinfo, query, or fragment whose origin exactly
  matches an allowlist entry; an empty allowlist rejects every callback.
- POST /api/v1/web/login-tickets/exchange answers CORS, checks PKCE S256,
  and issues a 30-day web:session tenant token (pandar_web_) that acts
  with the signed-in user's current role, like mobile:session, and
  cannot be minted manually.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T17:46:16.851811Z 2b981bb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The web exchange profile carried the token name ("Ares web"). Browser apps show who is signed in, so return the ticket creator's display name, as the plugin exchange does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@5aaee9
5aaee9 merged commit ef8d870 into main Nov 27, 2026
14 checks passed
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.

1 participant