Skip to content

Commit 952b0aa

Browse files
Rajatclaude
andcommitted
Add OAuth team selection for multi-team accounts (MCP)
Multi-team accounts connecting an OAuth/MCP client (e.g. Claude) had no way to specify a team: the only mechanism was the X-Sendlit-Team-Id header, which generic OAuth clients never send, so every /mcp call hit require-team.ts's 409 team_required response right after authorizing. Adds a "select a team" step to the OAuth flow via oauth-provider's postLogin hook, shown only for multi-team accounts (mirrors Notion's workspace picker) — the choice is threaded through as the OAuth referenceId and lands on the minted access token as a team_id claim, which resolve-auth.ts now re-validates as live membership before trusting. Single-team accounts are unaffected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent ec1bbaa commit 952b0aa

12 files changed

Lines changed: 5537 additions & 29 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATE TABLE IF NOT EXISTS "oauth_post_login_team_selections" (
2+
"session_id" text PRIMARY KEY NOT NULL,
3+
"team_id" uuid NOT NULL,
4+
"updated_at" timestamp with time zone DEFAULT now()
5+
);
6+
--> statement-breakpoint
7+
DO $$ BEGIN
8+
ALTER TABLE "oauth_post_login_team_selections" ADD CONSTRAINT "oauth_post_login_team_selections_session_id_auth_session_id_fk" FOREIGN KEY ("session_id") REFERENCES "public"."auth_session"("id") ON DELETE cascade ON UPDATE no action;
9+
EXCEPTION
10+
WHEN duplicate_object THEN null;
11+
END $$;
12+
--> statement-breakpoint
13+
DO $$ BEGIN
14+
ALTER TABLE "oauth_post_login_team_selections" ADD CONSTRAINT "oauth_post_login_team_selections_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;
15+
EXCEPTION
16+
WHEN duplicate_object THEN null;
17+
END $$;

0 commit comments

Comments
 (0)