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.

Update OAuth client references to OAuth app in codebase

Kiran K0021ad41a7b3
diff --git a/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts b/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts
index 58b753a7c5..3051288087 100644
--- a/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts
+++ b/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts
@@ -2,7 +2,7 @@ import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { NextResponse } from "next/server";
-// DELETE /api/oauth-clients/[clientId]/disconnect - Disconnect an authorized OAuth app from the workspace
+// DELETE /api/oauth-apps/[clientId]/disconnect - Disconnect an authorized OAuth app from the workspace
export const DELETE = withWorkspace(
async ({ params, workspace, session }) => {
const { clientId } = params;
diff --git a/apps/web/app/api/oauth-apps/[clientId]/route.ts b/apps/web/app/api/oauth-apps/[clientId]/route.ts
index 8276600f89..6cb276aec2 100644
--- a/apps/web/app/api/oauth-apps/[clientId]/route.ts
+++ b/apps/web/app/api/oauth-apps/[clientId]/route.ts
@@ -3,15 +3,15 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import {
- oAuthClientSchema,
+ oAuthAppSchema,
updateOAuthClientSchema,
} from "@/lib/zod/schemas/oauth";
import { NextResponse } from "next/server";
-// GET /api/oauth-clients/[clientId] – get an OAuth client
+// GET /api/oauth-apps/[clientId] – get an OAuth app
export const GET = withWorkspace(
async ({ params, workspace }) => {
- const app = await prisma.oAuthClient.findFirst({
+ const app = await prisma.oAuthApp.findFirst({
where: {
clientId: params.clientId,
projectId: workspace.id,
@@ -25,20 +25,20 @@ export const GET = withWorkspace(
});
}
- return NextResponse.json(oAuthClientSchema.parse(app));
+ return NextResponse.json(oAuthAppSchema.parse(app));
},
{
requiredScopes: ["oauth_apps.read"],
},
);
-// PATCH /api/oauth-clients/[clientId] – update an OAuth client
+// PATCH /api/oauth-apps/[clientId] – update an OAuth app
export const PATCH = withWorkspace(
async ({ req, params, workspace }) => {
const { name, developer, website, redirectUri, scopes } =
updateOAuthClientSchema.parse(await parseRequestBody(req));
- const app = await prisma.oAuthClient.update({
+ const app = await prisma.oAuthApp.update({
where: {
clientId: params.clientId,
projectId: workspace.id,
@@ -52,17 +52,17 @@ export const PATCH = withWorkspace(
},
});
- return NextResponse.json(oAuthClientSchema.parse(app));
+ return NextResponse.json(oAuthAppSchema.parse(app));
},
{
requiredScopes: ["oauth_apps.write"],
},
);
-// DELETE /api/oauth-clients/[clientId] - delete an OAuth client
+// DELETE /api/oauth-apps/[clientId] - delete an OAuth app
export const DELETE = withWorkspace(
async ({ params, workspace }) => {
- const app = await prisma.oAuthClient.findFirst({
+ const app = await prisma.oAuthApp.findFirst({
where: {
clientId: params.clientId,
projectId: workspace.id,
@@ -76,7 +76,7 @@ export const DELETE = withWorkspace(
});
}
- await prisma.oAuthClient.delete({
+ await prisma.oAuthApp.delete({
where: {
clientId: params.clientId,
},
diff --git a/apps/web/app/api/oauth-apps/authorized/route.ts b/apps/web/app/api/oauth-apps/authorized/route.ts
index 8eb10891bb..9951cda7c1 100644
--- a/apps/web/app/api/oauth-apps/authorized/route.ts
+++ b/apps/web/app/api/oauth-apps/authorized/route.ts
@@ -12,7 +12,7 @@ export const GET = withWorkspace(
select: {
id: true,
createdAt: true,
- oAuthClient: {
+ oAuthApp: {
select: {
clientId: true,
name: true,
@@ -32,10 +32,10 @@ export const GET = withWorkspace(
const appsAuthorized = result.map((app) => ({
id: app.id,
createdAt: app.createdAt,
- clientId: app.oAuthClient.clientId,
- name: app.oAuthClient.name,
- developer: app.oAuthClient.developer,
- website: app.oAuthClient.website,
+ clientId: app.oAuthApp.clientId,
+ name: app.oAuthApp.name,
+ developer: app.oAuthApp.developer,
+ website: app.oAuthApp.website,
user: {
id: app.user.id,
name: app.user.name,
diff --git a/apps/web/app/api/oauth-apps/route.ts b/apps/web/app/api/oauth-apps/route.ts
index 1d401e5f9e..594c7f9192 100644
--- a/apps/web/app/api/oauth-apps/route.ts
+++ b/apps/web/app/api/oauth-apps/route.ts
@@ -8,13 +8,13 @@ import { hashToken, withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import {
createOAuthClientSchema,
- oAuthClientSchema,
+ oAuthAppSchema,
} from "@/lib/zod/schemas/oauth";
import { nanoid } from "@dub/utils";
import { NextResponse } from "next/server";
import { z } from "zod";
-// POST /api/oauth-clients - create a new OAuth client
+// POST /api/oauth-apps - create a new OAuth apps
export const POST = withWorkspace(
async ({ req, workspace }) => {
const { name, developer, website, redirectUri, scopes } =
@@ -22,7 +22,7 @@ export const POST = withWorkspace(
const clientSecret = `${OAUTH_CLIENT_SECRET_PREFIX}${nanoid(OAUTH_CLIENT_SECRET_LENGTH)}`;
- const client = await prisma.oAuthClient.create({
+ const client = await prisma.oAuthApp.create({
data: {
projectId: workspace.id,
name,
@@ -37,7 +37,7 @@ export const POST = withWorkspace(
return NextResponse.json(
{
- ...oAuthClientSchema.parse(client),
+ ...oAuthAppSchema.parse(client),
clientSecret,
},
{ status: 201 },
@@ -48,16 +48,16 @@ export const POST = withWorkspace(
},
);
-// GET /api/oauth-clients - get all OAuth clients for a specific workspace
+// GET /api/oauth-apps - get all OAuth apps for a specific workspace
export const GET = withWorkspace(
async ({ workspace }) => {
- const clients = await prisma.oAuthClient.findMany({
+ const apps = await prisma.oAuthApp.findMany({
where: {
projectId: workspace.id,
},
});
- return NextResponse.json(z.array(oAuthClientSchema).parse(clients));
+ return NextResponse.json(z.array(oAuthAppSchema).parse(apps));
},
{
requiredScopes: ["oauth_apps.read"],
diff --git a/apps/web/app/api/oauth/authorize/route.ts b/apps/web/app/api/oauth/authorize/route.ts
index 9ce34fc066..d150841941 100644
--- a/apps/web/app/api/oauth/authorize/route.ts
+++ b/apps/web/app/api/oauth/authorize/route.ts
@@ -11,7 +11,7 @@ export const POST = withWorkspace(async ({ session, req, workspace }) => {
const body = authorizeRequestSchema.parse(await parseRequestBody(req));
const { state, client_id: clientId, redirect_uri: redirectUri } = body;
- const oAuthClient = await prisma.oAuthClient.findUniqueOrThrow({
+ const oAuthApp = await prisma.oAuthApp.findUniqueOrThrow({
where: {
clientId,
},
@@ -23,7 +23,7 @@ export const POST = withWorkspace(async ({ session, req, workspace }) => {
redirectUri,
projectId: workspace.id,
userId: session.user.id,
- scopes: oAuthClient.scopes,
+ scopes: oAuthApp.scopes,
code: nanoid(OAUTH_CODE_LENGTH),
expiresAt: new Date(Date.now() + OAUTH_CODE_LIFETIME * 1000),
},
diff --git a/apps/web/app/api/oauth/token/exchange-code-for-token.ts b/apps/web/app/api/oauth/token/exchange-code-for-token.ts
index ed81a81716..62d33e8b3d 100644
--- a/apps/web/app/api/oauth/token/exchange-code-for-token.ts
+++ b/apps/web/app/api/oauth/token/exchange-code-for-token.ts
@@ -43,7 +43,7 @@ export const exchangeAuthCodeForToken = async (
});
}
- const app = await prisma.oAuthClient.findFirst({
+ const app = await prisma.oAuthApp.findFirst({
where: {
clientId,
clientSecretHashed: await hashToken(clientSecret),
diff --git a/apps/web/app/api/oauth/token/refresh-access-token.ts b/apps/web/app/api/oauth/token/refresh-access-token.ts
index af2f3f9b1c..b0ecf3d17f 100644
--- a/apps/web/app/api/oauth/token/refresh-access-token.ts
+++ b/apps/web/app/api/oauth/token/refresh-access-token.ts
@@ -43,7 +43,7 @@ export const refreshAccessToken = async (
});
}
- const app = await prisma.oAuthClient.findFirst({
+ const app = await prisma.oAuthApp.findFirst({
where: {
clientId,
clientSecretHashed: await hashToken(clientSecret),
diff --git a/apps/web/lib/oauth.ts b/apps/web/lib/oauth.ts
index 98fe4a9251..af2eab3539 100644
--- a/apps/web/lib/oauth.ts
+++ b/apps/web/lib/oauth.ts
@@ -18,7 +18,7 @@ export const vaidateAuthorizeRequest = async (params: any) => {
const requestParams = request.data;
const { client_id: clientId, redirect_uri: redirectUri } = requestParams;
- const oAuthApp = await prisma.oAuthClient.findFirst({
+ const oAuthApp = await prisma.oAuthApp.findFirst({
where: {
clientId,
},
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index a6880d1ea2..39d1faab7d 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -3,10 +3,7 @@ import { metaTagsSchema } from "@/lib/zod/schemas/metatags";
import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
import { Link } from "@prisma/client";
import { createLinkBodySchema } from "./zod/schemas/links";
-import {
- oAuthAuthorizedAppSchema,
- oAuthClientSchema,
-} from "./zod/schemas/oauth";
+import { oAuthAppSchema, oAuthAuthorizedAppSchema } from "./zod/schemas/oauth";
import { tokenSchema } from "./zod/schemas/token";
export type LinkProps = Link;
@@ -199,7 +196,7 @@ export type MetaTag = z.infer<typeof metaTagsSchema>;
export type TokenProps = z.infer<typeof tokenSchema>;
-export type OAuthAppProps = z.infer<typeof oAuthClientSchema>;
+export type OAuthAppProps = z.infer<typeof oAuthAppSchema>;
export type OAuthAuthorizedAppProps = z.infer<
typeof oAuthAuthorizedAppSchema
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index 5cf77f4842..38d4115484 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -1,7 +1,7 @@
import { availableScopes } from "@/lib/api/tokens/scopes";
import { z } from "zod";
-export const oAuthClientSchema = z.object({
+export const oAuthAppSchema = z.object({
clientId: z.string(),
clientSecret: z.string().optional(),
name: z.string(),
@@ -94,7 +94,7 @@ export const oAuthAuthorizedAppSchema = z
}),
})
.merge(
- oAuthClientSchema.pick({
+ oAuthAppSchema.pick({
clientId: true,
name: true,
developer: true,
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index cd9daabf6a..f8b6145148 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -31,7 +31,7 @@ model User {
source String?
defaultWorkspace String?
oAuthCodes OAuthCode[]
- oAuthAuthorizedApps OAuthAuthorizedApp[] // OAuth clients user authorized for their workspace
+ oAuthAuthorizedApps OAuthAuthorizedApp[] // OAuth apps user authorized for their workspace
@@index(source)
@@index(defaultWorkspace)
@@ -108,7 +108,7 @@ model RestrictedToken {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
- oAuthClient OAuthClient? @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
+ oAuthApp OAuthApp? @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
refreshTokens OAuthRefreshToken[]
@@unique([userId, projectId, clientId])
@@ -153,8 +153,8 @@ model Project {
defaultDomains DefaultDomains[]
restrictedTokens RestrictedToken[]
oAuthCodes OAuthCode[]
- oAuthClients OAuthClient[] // OAuth clients workspace published
- oAuthAuthorizedApps OAuthAuthorizedApp[] // OAuth clients workspace authorized
+ oAuthApps OAuthApp[] // OAuth apps workspace published
+ oAuthAuthorizedApps OAuthAuthorizedApp[] // OAuth apps workspace authorized
@@index(usageLastChecked(sort: Asc))
}
@@ -365,7 +365,7 @@ model Customer {
@@index(externalId)
}
-model OAuthClient {
+model OAuthApp {
id String @id @default(cuid())
clientId String @unique
name String
@@ -399,9 +399,9 @@ model OAuthCode {
expiresAt DateTime
createdAt DateTime @default(now())
- oAuthClient OAuthClient @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
- project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ oAuthApp OAuthApp @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
}
model OAuthRefreshToken {
@@ -412,7 +412,7 @@ model OAuthRefreshToken {
expiresAt DateTime
createdAt DateTime @default(now())
- oAuthClient OAuthClient @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
+ oAuthApp OAuthApp @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
accessToken RestrictedToken @relation(fields: [accessTokenId], references: [id], onDelete: Cascade)
@@index(accessTokenId)
@@ -425,9 +425,9 @@ model OAuthAuthorizedApp {
userId String // user who granted access
createdAt DateTime @default(now())
- oAuthClient OAuthClient @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
- project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ oAuthApp OAuthApp @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@unique([userId, projectId, clientId])
}