Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

store code_challenge

Kiran K01a5df4f18fb
diff --git a/apps/web/app/api/oauth/authorize/route.ts b/apps/web/app/api/oauth/authorize/route.ts
index cfa31430a3..773da6cd13 100644
--- a/apps/web/app/api/oauth/authorize/route.ts
+++ b/apps/web/app/api/oauth/authorize/route.ts
@@ -14,9 +14,11 @@ import { NextResponse } from "next/server";
export const POST = withWorkspace(async ({ session, req, workspace }) => {
const {
state,
+ scope,
client_id: clientId,
redirect_uri: redirectUri,
- scope,
+ code_challenge: codeChallenge,
+ code_challenge_method: codeChallengeMethod,
} = authorizeRequestSchema.parse(await parseRequestBody(req));
const oAuthApp = await prisma.oAuthApp.findUniqueOrThrow({
@@ -40,6 +42,8 @@ export const POST = withWorkspace(async ({ session, req, workspace }) => {
userId: session.user.id,
scopes: scope.join(" "),
code: nanoid(OAUTH_CODE_LENGTH),
+ codeChallenge,
+ codeChallengeMethod,
expiresAt: new Date(Date.now() + OAUTH_CODE_LIFETIME * 1000),
},
});
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index a07ea02400..b6436132c8 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -69,6 +69,10 @@ export const authorizeRequestSchema = z.object({
message: "Invalid scopes",
},
),
+
+ // PKCE flow
+ code_challenge: z.string().max(255).optional(),
+ code_challenge_method: z.string().optional().default("plain"),
});
// Schema for OAuth2.0 code exchange request
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index c804c60ef8..6bcd69a862 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -399,6 +399,8 @@ model OAuthCode {
code String @unique
scopes String?
redirectUri String
+ codeChallenge String?
+ codeChallengeMethod String?
expiresAt DateTime
createdAt DateTime @default(now())