caelum0x ce55602f2b fix(toolgate): replace the dead "paste your Scribase session" OAuth sign-in with a real inline email-code flow
Real third-party MCP clients (Superhuman x3, Flowy, "Toffu") registered via
DCR and tried to sign in, but 0 ever completed: /oauth/authorize's sign-in
fallback was a form asking a human to paste a raw Scribase session token,
which no real user can produce. A redirect to console.scribase.com's login
was considered and rejected (plans/railyard.md 2026-11-12): console's own
session cookie is host-only and differently named (ry_session, not
scribase_session) and there is no cross-domain bridge, so that redirect
would just strand the user on the wrong subdomain.

Real fix: Toolgate now does its own two-step email-code sign-in, entirely
on toolgate.scribase.com, against the platform's own public, unauthenticated,
enumeration-safe magic-link endpoints
(POST {api}/v1/auth/builtin/magic-link/request + /verify) -- confirmed live
to return session.token in the exact shape ScribaseIdentity.user_from_session
already verifies via GET /v1/account, so no new verification path was
needed, only a new way to obtain the token.

- IdentityProvider gets 3 new methods (supports_email_signin,
  request_email_code, verify_email_code), all default-unimplemented (501)
  so dev's StaticIdentity is unaffected.
- ScribaseIdentity implements them against the real magic-link endpoints.
- New routes POST /oauth/signin/email and POST /oauth/signin/code; sign_in_page
  renders the real email form when the identity provider supports it (falls
  back to login_url() redirect, then the old paste form, for other
  deployments).
- Caught and fixed a real bug in the new code before it shipped: the
  session+clear-email Set-Cookie pair was built as an array literal, which
  axum's header IntoResponse impl inserts (last-wins), silently dropping the
  session cookie -- a new integration test driving the full email+code+
  redirect+consent flow caught it; fixed by appending both headers directly.
- 3 new unit tests (return_to/email/code validation) + 1 new end-to-end
  integration test (wrong code rejected, right code opens a session, reaches
  the real consent screen). cargo test --workspace: 0 failures.
2026-11-18 03:13:37 +03:00
..