Repository navigation
feat(hub): add web sign-in for allowlisted browser apps - #18
Merged
Merged
Conversation
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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Browser apps served from a
PANDAR_CORS_ALLOWED_ORIGINSorigin (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
GET /web-sign-in?redirect_url=<url>&code_challenge=<S256 base64url>&state=<opaque>/mobile-sign-in, with en and zh strings.redirect_url. If it is missing, the page shows an error state and makes no Hub call.createWebTicketserver action calls the Hub. It then redirects toredirect_urlwithticket,redirect_url, andstateappended.POST /api/v1/tenants/{tenant_id}/web/login-tickets{redirect_url, code_challenge}. Returns 201{ticket, expires_at, redirect_url}.invalid_code_challengevalidation are the same as the mobile route.LoginTicketKind::Web(stored kind"web"). Tickets use the prefixpandar_web_ticket_.httporhttps, with no userinfo, no query (including a bare?), and no fragment.Url::origin().ascii_serialization(), which matches the browserOriginheader) must exactly equal an allowlist entry. Any path is allowed.invalid_redirect_url.POST /api/v1/web/login-tickets/exchange{ticket, code_verifier}. Returns 200{token, expires_at, profile:{user_id,user_name,tenant_id,tenant_name}}.user_nameis the display name of the user who created the ticket, not the token name.{"error":"invalid_plugin_ticket"}.web:session(TenantTokenScope::WebSession), prefixpandar_web_, name"Ares web", and a 30-day TTL.web:sessionis special-cased everywheremobile:sessionis, through the newTenantTokenScope::is_user_session(). That covers session-user resolution,tenant_token_allows_role, and the rule that blocks manual token creation (invalid_scope).web_login_ticket.createandweb_login_ticket.exchange, with actor scopeweb:session.Originheader connects.contracts/hub-client.openapi.jsonadds both paths and the schemasWebLoginTicketRequest,WebTicketExchangeRequest, andWebTicketExchangeResponse. The TypeScript clients were regenerated. Kotlin is unchanged because these schemas are not Kotlin roots.scopesas plain strings with no enum, so the new scope needed no contract change.Test plan
routes::tests::web_sign_incovers:web:session) and ownerACAOheader on an exchange from the allowlisted originOriginheader/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.tsxcovers the missing-callback state, callback handoff for a single tenant and across tenant selection, and the form's hidden fields.actions.test.tscoverscreateWebTicketfor the redirect URL and for a Hub rejection.cargo clippy --workspace --all-targetsis clean, andnix fmtmade no changes. Thepandar-quality module-sizecheck passes.cargo nextest run --workspace: all 1298 tests outsidepandar-network-pluginpass. Thepandar-network-pluginStudio contract tests fail locally only becausereference/BambuStudiois not checked out.npm run test:web(263 passed),npm run typecheck:web,npm --prefix frontend run lint, andnpm run check:hub-clientspass.🤖 Generated with Claude Code