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.

enable and disable pkce option

Kiran Ke9123aaba07b
diff --git a/apps/web/app/api/oauth-apps/[clientId]/route.ts b/apps/web/app/api/oauth-apps/[clientId]/route.ts
index f22c74a36e..3ae5989e2d 100644
--- a/apps/web/app/api/oauth-apps/[clientId]/route.ts
+++ b/apps/web/app/api/oauth-apps/[clientId]/route.ts
@@ -32,7 +32,7 @@ export const GET = withWorkspace(
// PATCH /api/oauth-apps/[clientId] – update an OAuth app
export const PATCH = withWorkspace(
async ({ req, params, workspace }) => {
- const { name, developer, website, redirectUri, logo } =
+ const { name, developer, website, redirectUri, logo, pkce } =
updateOAuthAppSchema.parse(await parseRequestBody(req));
const app = await prisma.oAuthApp.update({
@@ -41,11 +41,12 @@ export const PATCH = withWorkspace(
projectId: workspace.id,
},
data: {
- ...(name && { name }),
- ...(developer && { developer }),
- ...(website && { website }),
- ...(redirectUri && { redirectUri }),
- ...(logo && { logo }),
+ name,
+ developer,
+ website,
+ redirectUri,
+ logo,
+ pkce,
},
});
diff --git a/apps/web/app/api/oauth-apps/route.ts b/apps/web/app/api/oauth-apps/route.ts
index d55f54db54..1a404a4ddb 100644
--- a/apps/web/app/api/oauth-apps/route.ts
+++ b/apps/web/app/api/oauth-apps/route.ts
@@ -14,7 +14,7 @@ import { z } from "zod";
// POST /api/oauth-apps - create a new OAuth app
export const POST = withWorkspace(
async ({ req, workspace, session }) => {
- const { name, developer, website, redirectUri, logo } =
+ const { name, developer, website, redirectUri, logo, pkce } =
createOAuthAppSchema.parse(await parseRequestBody(req));
const clientSecret = `${OAUTH_CLIENT_SECRET_PREFIX}${nanoid(OAUTH_CLIENT_SECRET_LENGTH)}`;
@@ -30,6 +30,7 @@ export const POST = withWorkspace(
clientId: nanoid(OAUTH_CLIENT_ID_LENGTH),
clientSecretHashed: await hashToken(clientSecret),
createdBy: session.user.id,
+ pkce,
},
});
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index 58dbaf7418..99eb2995b2 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -34,6 +34,7 @@ export const createOAuthAppSchema = z.object({
"redirect_uri must be a valid URL starting with 'https://' except for 'http://localhost'",
},
),
+ pkce: z.boolean().default(false),
});
export const updateOAuthAppSchema = createOAuthAppSchema.partial();
@@ -46,6 +47,7 @@ export const oAuthAppSchema = z.object({
website: z.string(),
redirectUri: z.string(),
logo: z.string().nullable(),
+ pkce: z.boolean(),
});
// Schema for OAuth2.0 Authorization request
diff --git a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx b/apps/web/ui/modals/add-edit-oauth-app-modal.tsx
index 7871cecd7a..4c35d13477 100644
--- a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx
+++ b/apps/web/ui/modals/add-edit-oauth-app-modal.tsx
@@ -7,6 +7,7 @@ import {
InfoTooltip,
Logo,
Modal,
+ Switch,
} from "@dub/ui";
import {
Dispatch,
@@ -26,6 +27,7 @@ const newApp: OAuthAppProps = {
clientId: "",
redirectUri: "",
logo: null,
+ pkce: false,
};
function AddEditAppModal({
@@ -86,7 +88,7 @@ function AddEditAppModal({
}
};
- const { name, developer, website, redirectUri, logo } = data;
+ const { name, developer, website, redirectUri, logo, pkce } = data;
const buttonDisabled = !name || !developer || !website || !redirectUri;
return (
@@ -214,6 +216,19 @@ function AddEditAppModal({
</div>
</div>
+ <div className="flex items-center justify-between pb-4">
+ <label htmlFor="pkce" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Allow PKCE</h2>
+ <InfoTooltip content="We strongly recommend using the PKCE flow for increased security" />
+ </label>
+ <Switch
+ checked={pkce}
+ fn={(value: boolean) => {
+ setData({ ...data, pkce: value });
+ }}
+ />
+ </div>
+
<Button
text={app ? "Save changes" : "Create"}
disabled={buttonDisabled}