Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 158 additions & 2 deletions packages/api-client/src/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
// Generated from packages/docs/openapi.yaml. Do not edit.
export interface paths {
"/api/v1/auth/connections": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Persist an individual validated MCP connection; sets a per-attempt browser cookie
* @description Cookie-only browser operation. Mutations require an exact app Origin and reject cross-site requests. Authorization headers are rejected. Responses are never cached.
*/
post: operations["post_api_v1_auth_connections"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/auth/connections/resume": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Resume verified onboarding in the initiating browser; never grants OAuth access
* @description Cookie-only browser operation. Mutations require an exact app Origin and reject cross-site requests. Authorization headers are rejected. Responses are never cached.
*/
post: operations["post_api_v1_auth_connections_resume"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/session": {
parameters: {
query?: never;
Expand Down Expand Up @@ -90,7 +130,7 @@ export interface paths {
get?: never;
put?: never;
/**
* Complete email verification
* Verify email, establish an owner session, and resume explicit consent; callbacks stay in the initiating browser
* @description Cookie-only browser operation. Mutations require an exact app Origin and reject cross-site requests. Authorization headers are rejected. Responses are never cached.
*/
post: operations["post_api_v1_auth_email_verification_complete"];
Expand Down Expand Up @@ -130,7 +170,7 @@ export interface paths {
get?: never;
put?: never;
/**
* Complete password reset
* Complete password reset and resume onboarding
* @description Cookie-only browser operation. Mutations require an exact app Origin and reject cross-site requests. Authorization headers are rejected. Responses are never cached.
*/
post: operations["post_api_v1_auth_password_reset_complete"];
Expand Down Expand Up @@ -1883,6 +1923,100 @@ export interface components {
}
export type $defs = Record<string, never>;
export interface operations {
post_api_v1_auth_connections: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
returnTo: string;
};
};
};
responses: {
/** @description Success */
200: {
headers: {
/** @description Conditions-only webhook runtime deployment marker. */
"X-Factorize-Webhook-Conditions"?: "v1";
/** @description Deployment compatibility marker for the complete GEN-2157 static-client API contract. Deploy this API stage before static frontend cutover. */
"X-Factorize-Contract"?: "gen-2157-static-v1";
[name: string]: unknown;
};
content: {
"application/json": {
/** Format: uuid */
connection: string;
clientName: string;
/** Format: date-time */
expiresAt: string;
};
};
};
400: components["responses"]["Error400"];
401: components["responses"]["Error401"];
403: components["responses"]["Error403"];
404: components["responses"]["Error404"];
409: components["responses"]["Error409"];
415: components["responses"]["Error415"];
429: components["responses"]["Error429"];
500: components["responses"]["Error500"];
503: components["responses"]["Error503"];
};
};
post_api_v1_auth_connections_resume: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
/** Format: uuid */
connection: string;
};
};
};
responses: {
/** @description Success */
200: {
headers: {
/** @description Conditions-only webhook runtime deployment marker. */
"X-Factorize-Webhook-Conditions"?: "v1";
/** @description Deployment compatibility marker for the complete GEN-2157 static-client API contract. Deploy this API stage before static frontend cutover. */
"X-Factorize-Contract"?: "gen-2157-static-v1";
[name: string]: unknown;
};
content: {
"application/json": {
/** @constant */
ok: true;
returnTo?: string;
crossBrowser?: boolean;
pending?: boolean;
clientName?: string;
/** Format: date-time */
expiresAt?: string;
};
};
};
400: components["responses"]["Error400"];
401: components["responses"]["Error401"];
403: components["responses"]["Error403"];
404: components["responses"]["Error404"];
409: components["responses"]["Error409"];
415: components["responses"]["Error415"];
429: components["responses"]["Error429"];
500: components["responses"]["Error500"];
503: components["responses"]["Error503"];
};
};
get_api_v1_session: {
parameters: {
query?: never;
Expand Down Expand Up @@ -1949,6 +2083,8 @@ export interface operations {
email: string;
password: string;
returnTo?: string;
/** Format: uuid */
connection?: string;
};
};
};
Expand Down Expand Up @@ -1994,6 +2130,8 @@ export interface operations {
/** Format: email */
email: string;
password: string;
/** Format: uuid */
connection?: string;
};
};
};
Expand Down Expand Up @@ -2037,6 +2175,8 @@ export interface operations {
"application/json": {
/** Format: email */
email: string;
/** Format: uuid */
connection?: string;
};
};
};
Expand Down Expand Up @@ -2096,6 +2236,12 @@ export interface operations {
"application/json": {
/** @constant */
ok: true;
returnTo?: string;
crossBrowser?: boolean;
pending?: boolean;
clientName?: string;
/** Format: date-time */
expiresAt?: string;
};
};
};
Expand All @@ -2122,6 +2268,8 @@ export interface operations {
"application/json": {
/** Format: email */
email: string;
/** Format: uuid */
connection?: string;
};
};
};
Expand Down Expand Up @@ -2182,6 +2330,12 @@ export interface operations {
"application/json": {
/** @constant */
ok: true;
returnTo?: string;
crossBrowser?: boolean;
pending?: boolean;
clientName?: string;
/** Format: date-time */
expiresAt?: string;
};
};
};
Expand Down Expand Up @@ -2300,6 +2454,7 @@ export interface operations {
clientName: string;
scopes: string[];
expiresAt: string;
signature: string;
};
};
};
Expand All @@ -2325,6 +2480,7 @@ export interface operations {
content: {
"application/json": {
userCode: string;
signature: string;
/** @enum {string} */
decision: "allow" | "deny";
};
Expand Down
23 changes: 23 additions & 0 deletions packages/api/migrations/0014_oauth_onboarding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Individual browser-bound requests survive email delivery without sharing a return cookie.
CREATE TABLE app.oauth_connections (
id uuid PRIMARY KEY,
browser_digest text NOT NULL,
destination text NOT NULL,
device_user_code text,
client_name text NOT NULL,
kind text NOT NULL CHECK (kind IN ('callback','device')),
expires_at timestamptz NOT NULL,
user_id uuid REFERENCES app.auth_users(id) ON DELETE CASCADE,
ready_version integer,
ready boolean NOT NULL DEFAULT false,
used_at timestamptz
);
ALTER TABLE app.auth_reset_tokens ADD COLUMN connection_id uuid REFERENCES app.oauth_connections(id) ON DELETE SET NULL;
CREATE TABLE app.oauth_consent_previews (
id uuid PRIMARY KEY,
expires_at timestamptz NOT NULL,
used_at timestamptz
);

CREATE INDEX oauth_connections_expires ON app.oauth_connections(expires_at);
CREATE INDEX oauth_consent_previews_expires ON app.oauth_consent_previews(expires_at);
12 changes: 7 additions & 5 deletions packages/api/src/api-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "./flow-schemas";
import { traceReplaySchema } from "./trace-replay-schemas";
import document from "./api-document.json";
import { authInputs, authSuccess, loginSuccess, sessionResponse, type AuthAction } from "./auth-api";
import { authInputs, authSuccess, continuationSuccess, connectionStartInput, connectionStartSuccess, connectionResumeInput, loginSuccess, sessionResponse, type AuthAction } from "./auth-api";

type JsonSchema = Record<string, any>;
export interface RouteContract {
Expand Down Expand Up @@ -165,18 +165,20 @@ function authRoute(method: string, path: string, action: AuthAction, summary: st
}

export const API_ROUTES: RouteContract[] = [
authRoute("POST", "/api/v1/auth/connections", "connection-start", "Persist an individual validated MCP connection; sets a per-attempt browser cookie", connectionStartSuccess, connectionStartInput),
authRoute("POST", "/api/v1/auth/connections/resume", "connection-resume", "Resume verified onboarding in the initiating browser; never grants OAuth access", continuationSuccess, connectionResumeInput),
authRoute("GET", "/api/v1/session", "session", "Get current browser session", sessionResponse),
authRoute("POST", "/api/v1/auth/login", "login", "Sign in", loginSuccess, authInputs.login),
authRoute("POST", "/api/v1/auth/signup", "signup", "Request signup; existing accounts return the same accepted response", authSuccess, authInputs.signup, 202),
authRoute("POST", "/api/v1/auth/email-verification/request", "verification-request", "Request email verification", authSuccess, authInputs.request),
authRoute("POST", "/api/v1/auth/email-verification/complete", "verification", "Complete email verification", authSuccess, authInputs.verify),
authRoute("POST", "/api/v1/auth/email-verification/complete", "verification", "Verify email, establish an owner session, and resume explicit consent; callbacks stay in the initiating browser", continuationSuccess, authInputs.verify),
authRoute("POST", "/api/v1/auth/password-reset/request", "reset-request", "Request password reset", authSuccess, authInputs.request),
authRoute("POST", "/api/v1/auth/password-reset/complete", "reset", "Complete password reset", authSuccess, authInputs.reset),
authRoute("POST", "/api/v1/auth/password-reset/complete", "reset", "Complete password reset and resume onboarding", continuationSuccess, authInputs.reset),
authRoute("POST", "/api/v1/auth/password", "password", "Change password and invalidate sessions", authSuccess, authInputs.change),
authRoute("POST", "/api/v1/auth/logout", "logout", "Revoke current session and clear browser cookie", authSuccess),

route("POST", "/api/v1/oauth/device/preview", "flows:read", { summary: "Inspect a device authorization code", responses: { "200": { description: "Pending device request", content: { "application/json": { schema: jsonSchema(z.object({ userCode: z.string(), clientName: z.string(), scopes: z.array(z.string()), expiresAt: z.string() }), "output") } } } } }, async () => undefined, { body: z.object({ userCode: z.string().min(1).max(32) }).strict(), authOperation: "device-preview", ownerSession: true }),
route("POST", "/api/v1/oauth/device/decision", "flows:write", { summary: "Approve or deny a device authorization code", responses: { "200": { description: "Device decision", content: { "application/json": { schema: jsonSchema(z.object({ status: z.enum(["approved", "denied"]) }), "output") } } } } }, async () => undefined, { body: z.object({ userCode: z.string().min(1).max(32), decision: z.enum(["allow", "deny"]) }).strict(), authOperation: "device-decision", ownerSession: true }),
route("POST", "/api/v1/oauth/device/preview", "flows:read", { summary: "Inspect a device authorization code", responses: { "200": { description: "Pending device request", content: { "application/json": { schema: jsonSchema(z.object({ userCode: z.string(), clientName: z.string(), scopes: z.array(z.string()), expiresAt: z.string(), signature: z.string() }), "output") } } } } }, async () => undefined, { body: z.object({ userCode: z.string().min(1).max(32) }).strict(), authOperation: "device-preview", ownerSession: true }),
route("POST", "/api/v1/oauth/device/decision", "flows:write", { summary: "Approve or deny a device authorization code", responses: { "200": { description: "Device decision", content: { "application/json": { schema: jsonSchema(z.object({ status: z.enum(["approved", "denied"]) }), "output") } } } } }, async () => undefined, { body: z.object({ userCode: z.string().min(1).max(32), signature: z.string().min(1).max(256), decision: z.enum(["allow", "deny"]) }).strict(), authOperation: "device-decision", ownerSession: true }),
route("POST", "/api/v1/oauth/consent/preview", "flows:read", { summary: "Inspect an OAuth consent request", responses: { "200": { description: "Owner-bound expiring consent", content: { "application/json": { schema: jsonSchema(consentPreviewResponse, "output") } } } } }, async () => undefined, { body: consentPreviewInput, authOperation: "consent-preview", ownerSession: true }),
route("POST", "/api/v1/oauth/consent/decision", "flows:write", { summary: "Decide an OAuth consent request", responses: { "200": { description: "Validated protocol destination", content: { "application/json": { schema: jsonSchema(consentDecisionResponse, "output") } } } } }, async () => undefined, { body: consentDecisionInput, authOperation: "consent-decision", ownerSession: true }),
route("GET", "/api/v1/trigger-contexts", "flows:read", {
Expand Down
Loading
Loading