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.

Updates to PKCE flow

Kiran Kf950e4f3ae7e
diff --git a/apps/web/app/api/oauth/apps/route.ts b/apps/web/app/api/oauth/apps/route.ts
index 3375382d78..0a359620fc 100644
--- a/apps/web/app/api/oauth/apps/route.ts
+++ b/apps/web/app/api/oauth/apps/route.ts
@@ -70,10 +70,12 @@ export const POST = withWorkspace(
prefix: OAUTH_CONFIG.CLIENT_ID_PREFIX,
});
- const clientSecret = createToken({
- length: OAUTH_CONFIG.CLIENT_SECRET_LENGTH,
- prefix: OAUTH_CONFIG.CLIENT_SECRET_PREFIX,
- });
+ const clientSecret = !pkce
+ ? createToken({
+ length: OAUTH_CONFIG.CLIENT_SECRET_LENGTH,
+ prefix: OAUTH_CONFIG.CLIENT_SECRET_PREFIX,
+ })
+ : undefined;
try {
let logoUrl: string | undefined;
@@ -100,8 +102,10 @@ export const POST = withWorkspace(
readme,
redirectUris,
clientId,
- hashedClientSecret: await hashToken(clientSecret),
- partialClientSecret: `dub_app_secret_****${clientSecret.slice(-8)}`,
+ hashedClientSecret: clientSecret ? await hashToken(clientSecret) : "",
+ partialClientSecret: clientSecret
+ ? `dub_app_secret_****${clientSecret.slice(-8)}`
+ : "",
userId: session.user.id,
pkce,
...(logoUrl && { logo: logoUrl }),
@@ -111,7 +115,7 @@ export const POST = withWorkspace(
return NextResponse.json(
{
...oAuthAppSchema.parse(app),
- clientSecret,
+ ...(clientSecret && { clientSecret }),
},
{ status: 201 },
);
diff --git a/apps/web/ui/integrations/add-edit-integration-form.tsx b/apps/web/ui/integrations/add-edit-integration-form.tsx
index e591284a55..dded992bad 100644
--- a/apps/web/ui/integrations/add-edit-integration-form.tsx
+++ b/apps/web/ui/integrations/add-edit-integration-form.tsx
@@ -106,9 +106,11 @@ export default function AddEditIntegrationForm({
toast.success(endpoint.successMessage);
if (endpoint.method === "POST") {
- router.push(
- `/${workspaceSlug}/integrations/manage/${result.id}?client_secret=${result.clientSecret}`,
- );
+ const url = `/${workspaceSlug}/integrations/manage/${result.id}${
+ result.clientSecret ? `?client_secret=${result.clientSecret}` : ""
+ }`;
+
+ router.push(url);
}
} else {
toast.error(result.error.message);
diff --git a/apps/web/ui/integrations/oauth-app-credentials.tsx b/apps/web/ui/integrations/oauth-app-credentials.tsx
index 17c0c4cbc6..5ddd4f63a5 100644
--- a/apps/web/ui/integrations/oauth-app-credentials.tsx
+++ b/apps/web/ui/integrations/oauth-app-credentials.tsx
@@ -27,7 +27,7 @@ export default function OAuthAppCredentials({
</div>
</div>
- {clientSecret ? (
+ {clientSecret && (
<div className="space-y-2">
<label className="text-sm font-medium text-gray-500">
Client Secret
@@ -45,7 +45,9 @@ export default function OAuthAppCredentials({
again.
</span>
</div>
- ) : (
+ )}
+
+ {!clientSecret && partialClientSecret && (
<div className="space-y-2">
<label className="text-sm font-medium text-gray-500">
Client Secret