Skip to content

Commit 570e6dc

Browse files
committed
redirect on OIDC return
1 parent ed1301f commit 570e6dc

File tree

3 files changed

+54
-94
lines changed

3 files changed

+54
-94
lines changed

app/callback/route.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

app/login/vercel/callback/route.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { cookies as getCookies } from "next/headers";
22
import { getTokens } from "../issuer";
3+
import { createSession } from "@/app/dashboard/auth";
4+
import { redirect } from "next/navigation";
35

46
export async function GET(req: Request) {
57
const url = req.url;
@@ -12,11 +14,44 @@ export async function GET(req: Request) {
1214
console.log("Callback:", { url, expectedState });
1315

1416
const { id_token, claims } = (await getTokens(url, expectedState)) || {};
17+
console.log("OIDC Callback:", { id_token, claims, v_deeplink });
1518

1619
if (id_token) {
17-
cookies.set("id-token", id_token);
20+
createSession(id_token);
1821
}
1922

20-
// TODO: redirect to the /dashboard based on v_deeplink.
21-
return Response.json({ id_token, claims, v_deeplink });
23+
const deepLinkParams = new URLSearchParams(v_deeplink || "");
24+
25+
const resourceId = deepLinkParams.get("resource_id");
26+
const projectId = deepLinkParams.get("project_id");
27+
const invoiceId = deepLinkParams.get("invoice_id");
28+
const checkId = deepLinkParams.get("check_id");
29+
30+
if (invoiceId) {
31+
return redirect(`/dashboard/invoices?id=${invoiceId}`);
32+
}
33+
34+
if (deepLinkParams.get("support")) {
35+
return redirect(
36+
`/dashboard/support${resourceId ? "?resource_id=" + resourceId : ""}`
37+
);
38+
}
39+
40+
if (resourceId) {
41+
if (projectId) {
42+
if (checkId) {
43+
return redirect(
44+
`/dashboard/resources/${resourceId}/projects/${projectId}?checkId=${encodeURIComponent(checkId)}`
45+
);
46+
}
47+
48+
return redirect(
49+
`/dashboard/resources/${resourceId}/projects/${projectId}`
50+
);
51+
}
52+
53+
return redirect(`/dashboard/resources/${resourceId}`);
54+
}
55+
56+
redirect("/dashboard");
2257
}

lib/vercel/marketplace-api.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export async function createCheck(
102102
method: "POST",
103103
installationId: installation_id,
104104
data: {
105-
source: { kind: 'integration', externalResourceId: resource_id },
105+
source: { kind: "integration", externalResourceId: resource_id },
106106
name,
107107
isRerequestable: isRerequestable === "on",
108108
requires,
@@ -119,17 +119,26 @@ export async function updateCheckRun(
119119
deploymentId: string,
120120
updates: {
121121
status: "queued" | "running" | "completed";
122-
conclusion?: "canceled" | "skipped" | "timeout" | "failed" | "neutral" | "succeeded";
122+
conclusion?:
123+
| "canceled"
124+
| "skipped"
125+
| "timeout"
126+
| "failed"
127+
| "neutral"
128+
| "succeeded";
123129
externalId?: string;
124130
externalUrl?: string;
125131
output?: unknown;
126132
}
127133
) {
128-
await fetchVercelApi(`/v2/deployments/${deploymentId}/check-runs/${checkRunId}`, {
129-
method: "PATCH",
130-
installationId: installation_id,
131-
data: updates,
132-
});
134+
await fetchVercelApi(
135+
`/v2/deployments/${deploymentId}/check-runs/${checkRunId}`,
136+
{
137+
method: "PATCH",
138+
installationId: installation_id,
139+
data: updates,
140+
}
141+
);
133142
}
134143

135144
export async function getProjectChecks(
@@ -168,29 +177,6 @@ export async function updateSecrets(
168177
);
169178
}
170179

171-
const IntegrationsSsoTokenResponse = z.object({
172-
id_token: z.string(),
173-
});
174-
175-
export async function exchangeCodeForToken(
176-
code: string,
177-
state: string | null | undefined
178-
): Promise<string> {
179-
const { id_token } = IntegrationsSsoTokenResponse.parse(
180-
await fetchVercelApi("/v1/integrations/sso/token", {
181-
method: "POST",
182-
data: {
183-
code,
184-
state,
185-
client_id: env.INTEGRATION_CLIENT_ID,
186-
client_secret: env.INTEGRATION_CLIENT_SECRET,
187-
},
188-
})
189-
);
190-
191-
return id_token;
192-
}
193-
194180
export async function importResource(
195181
installationId: string,
196182
resourceId: string,

0 commit comments

Comments
 (0)