Skip to content
Draft
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
Binary file added docs/screenshots/catalog-oauth-setup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/api/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ describe("registerCatalogServer", () => {
});
});

it("preserves OAuth credentials in the catalog registration body", async () => {
let body: unknown;
server.use(
http.post("*/api/v1/catalog/:catalogId/register", async ({ request }) => {
body = await request.json();
return HttpResponse.json({ success: true, server_id: "gateway-1", message: "Registered" });
}),
);

await registerCatalogServer("github", {
oauth_credentials: {
grant_type: "authorization_code",
issuer: "https://github.com",
client_id: "client-id",
client_secret: "client-secret", // pragma: allowlist secret
authorization_url: "https://github.com/login/oauth/authorize",
token_url: "https://github.com/login/oauth/access_token",
scopes: ["repo"],
},
});

expect(body).toEqual({
oauth_credentials: {
grant_type: "authorization_code",
issuer: "https://github.com",
client_id: "client-id",
client_secret: "client-secret", // pragma: allowlist secret
authorization_url: "https://github.com/login/oauth/authorize",
token_url: "https://github.com/login/oauth/access_token",
scopes: ["repo"],
},
});
});

it("DELETEs an encoded gateway ID and preserves async lifecycle metadata", async () => {
let requestPath = "";
server.use(
Expand Down
33 changes: 32 additions & 1 deletion src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,37 @@ import type {
GatewayTestResponse,
} from "@/generated/types";

/** Temporary handwritten contract until #6588 reaches generated OpenAPI types. */
export interface CatalogOAuthCredentials {
grant_type: "authorization_code";
issuer: string;
client_id: string;
client_secret: string; // pragma: allowlist secret
authorization_url: string;
token_url: string;
scopes: string[];
}

export type CatalogOAuthRegisterBody = CatalogServerRegisterBody & {
oauth_credentials: CatalogOAuthCredentials;
};

export interface OAuthUserTokenStatus {
status: "valid" | "near_expiry" | "expired" | "missing";
authorized: boolean;
scopes?: string[];
expires_at?: string | null;
updated_at?: string | null;
}

export interface OAuthGatewayStatus {
oauth_enabled: boolean;
grant_type?: string;
user_token_status?: OAuthUserTokenStatus;
}

export type OAuthGatewayStatusMap = Record<string, OAuthGatewayStatus>;

export interface GatewayImpactPreview {
gatewayId: string;
servers: Array<{ id: string; name: string }>;
Expand All @@ -17,7 +48,7 @@ export type CatalogGatewayDeleteResponse = GatewayRead | { status?: string; mess
/** Register a catalog entry through the authenticated BFF proxy. */
export async function registerCatalogServer(
catalogId: string,
body?: CatalogServerRegisterBody,
body?: CatalogServerRegisterBody | CatalogOAuthRegisterBody,
): Promise<CatalogServerRegisterResponse> {
return api.post<CatalogServerRegisterResponse>(
`/v1/catalog/${encodeURIComponent(catalogId)}/register`,
Expand Down
Loading