peppa/packages/db/migrations/0006_crazy_stellaris.sql
Асель 39367b1d82 PEP-8: remote MCP for ChatGPT with Peppa as OAuth 2.1 server
- OAuth: RFC 8414/9728 metadata, RFC 7591 dynamic registration,
  authorization code + PKCE S256 with a consent screen after Gitea login,
  refresh token rotation; tokens and codes stored hashed; revoke in web
- /mcp: stateless Streamable HTTP, Bearer → user; PM tools from
  @peppa/mcp/manager: projects, goals, tasks, create, move (board
  semantics, starts agents), inbox, answer/accept — owner-scoped
- login keeps ?next= through Gitea OAuth; Settings page with MCP URL and
  connected apps
- 5 new tests (53 e2e total, green); verified on prod as a client:
  DCR → consent → token → MCP over HTTPS → revoke → 401
- OpenSpec: pep-8 archived into spec remote-mcp

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:38:09 +05:00

34 lines
1.7 KiB
SQL

CREATE TABLE "oauth_clients" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"redirect_uris" jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "oauth_codes" (
"code_hash" text PRIMARY KEY NOT NULL,
"client_id" text NOT NULL,
"user_id" integer NOT NULL,
"redirect_uri" text NOT NULL,
"code_challenge" text NOT NULL,
"scope" text,
"expires_at" timestamp with time zone NOT NULL,
"used_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "oauth_tokens" (
"token_hash" text PRIMARY KEY NOT NULL,
"kind" text NOT NULL,
"client_id" text NOT NULL,
"user_id" integer NOT NULL,
"scope" text,
"expires_at" timestamp with time zone NOT NULL,
"revoked_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"last_used_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "oauth_codes" ADD CONSTRAINT "oauth_codes_client_id_oauth_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."oauth_clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_codes" ADD CONSTRAINT "oauth_codes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_tokens" ADD CONSTRAINT "oauth_tokens_client_id_oauth_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."oauth_clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_tokens" ADD CONSTRAINT "oauth_tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;