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.

list OAuth Applications

Kiran K57a4c17c7c07
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/layout.tsx
index 1528aae23f..1c9c43a296 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/layout.tsx
@@ -23,6 +23,10 @@ export default function WorkspaceSettingsLayout({
name: "API Keys",
segment: "tokens",
},
+ {
+ name: "OAuth Apps",
+ segment: "oauth-apps",
+ },
{
name: "Security",
segment: "security",
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx
new file mode 100644
index 0000000000..165a66b3a3
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx
@@ -0,0 +1,171 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import { OAuthClientProps } from "@/lib/types";
+import { useAddEditTokenModal } from "@/ui/modals/add-edit-token-modal";
+import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";
+import EmptyState from "@/ui/shared/empty-state";
+import { Delete } from "@/ui/shared/icons";
+import { Button, LoadingSpinner, Popover, TokenAvatar } from "@dub/ui";
+import { Key } from "@dub/ui/src/icons";
+import { fetcher, timeAgo } from "@dub/utils";
+import { Edit3, MoreVertical } from "lucide-react";
+import { useState } from "react";
+import useSWR from "swr";
+
+export default function OAuthAppPageClient() {
+ const { id: workspaceId } = useWorkspace();
+ const { data: clients, isLoading } = useSWR<OAuthClientProps[]>(
+ `/api/oauth-clients?workspaceId=${workspaceId}`,
+ fetcher,
+ );
+
+ const [createdToken, setCreatedToken] = useState<string | null>(null);
+ const { TokenCreatedModal, setShowTokenCreatedModal } = useTokenCreatedModal({
+ token: createdToken || "",
+ });
+
+ const onTokenCreated = (token: string) => {
+ setCreatedToken(token);
+ setShowTokenCreatedModal(true);
+ };
+
+ const { AddEditTokenModal, AddTokenButton } = useAddEditTokenModal({
+ onTokenCreated,
+ });
+
+ return (
+ <>
+ <TokenCreatedModal />
+ <AddEditTokenModal />
+ <div className="rounded-lg border border-gray-200 bg-white">
+ <div className="flex flex-col items-center justify-between gap-4 space-y-3 border-b border-gray-200 p-5 sm:flex-row sm:space-y-0 sm:p-10">
+ <div className="flex max-w-screen-sm flex-col space-y-3">
+ <h2 className="text-xl font-medium">OAuth Applications</h2>
+ <p className="text-sm text-gray-500">
+ Applications owned by your workspace. You can use OAuth app to
+ build integrations that extend the Dub's functionality.{" "}
+ <a
+ href="https://dub.co/docs/api-reference/tokens"
+ target="_blank"
+ className="font-medium underline underline-offset-4 hover:text-black"
+ >
+ Learn more
+ </a>
+ </p>
+ </div>
+ <AddTokenButton />
+ </div>
+ {isLoading || !clients ? (
+ <div className="flex flex-col items-center justify-center space-y-4 py-20">
+ <LoadingSpinner className="h-6 w-6 text-gray-500" />
+ <p className="text-sm text-gray-500">Fetching API keys...</p>
+ </div>
+ ) : clients.length > 0 ? (
+ <div>
+ <div className="grid grid-cols-5 border-b border-gray-200 px-5 py-2 text-sm font-medium text-gray-500 sm:px-10">
+ <div className="col-span-4">Name</div>
+ <div className="text-center">Last updated</div>
+ </div>
+ <div className="divide-y divide-gray-200">
+ {clients.map((token) => (
+ <OAuthClientRow key={token.clientId} {...token} />
+ ))}
+ </div>
+ </div>
+ ) : (
+ <div className="flex flex-col items-center justify-center gap-y-4 py-20">
+ <EmptyState
+ icon={Key}
+ title="No API keys found for this workspace"
+ />
+ <AddTokenButton />
+ </div>
+ )}
+ </div>
+ </>
+ );
+}
+
+const OAuthClientRow = (oauthClient: OAuthClientProps) => {
+ const [openPopover, setOpenPopover] = useState(false);
+
+ // const { setShowAddEditTokenModal, AddEditTokenModal } = useAddEditTokenModal({
+ // token: {
+ // id: token.id,
+ // name: token.name,
+ // isMachine: token.user.isMachine,
+ // scopes: mapScopesToResource(token.scopes),
+ // },
+ // });
+
+ // const { DeleteTokenModal, setShowDeleteTokenModal } = useDeleteTokenModal({
+ // token,
+ // });
+
+ return (
+ <>
+ {/* <AddEditTokenModal />
+ <DeleteTokenModal /> */}
+ <div className="relative grid grid-cols-5 items-center px-5 py-3 sm:px-10">
+ <div className="col-span-4 flex items-center space-x-3">
+ <TokenAvatar id={oauthClient.clientId} />
+ <div className="flex flex-col space-y-px">
+ <p className="font-semibold text-gray-700">{oauthClient.name}</p>
+ <div className="flex items-center gap-x-2">
+ <p className="text-sm text-gray-500" suppressHydrationWarning>
+ {oauthClient.scopes.length} access scopes
+ </p>
+ </div>
+ </div>
+ </div>
+ <div
+ className="text-center text-sm text-gray-500"
+ suppressHydrationWarning
+ >
+ {timeAgo(oauthClient.updatedAt, { withAgo: true })}
+ </div>
+ <Popover
+ content={
+ <div className="w-full sm:w-48">
+ <div className="grid gap-px p-2">
+ <Button
+ text="Edit API Key"
+ variant="outline"
+ icon={<Edit3 className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ onClick={() => {
+ setOpenPopover(false);
+ // setShowAddEditTokenModal(true);
+ }}
+ />
+ <Button
+ text="Delete API Key"
+ variant="danger-outline"
+ icon={<Delete className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ onClick={() => {
+ setOpenPopover(false);
+ // setShowDeleteTokenModal(true);
+ }}
+ />
+ </div>
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <button
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ className="absolute right-4 rounded-md px-1 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <MoreVertical className="h-5 w-5 text-gray-500" />
+ </button>
+ </Popover>
+ </div>
+ </>
+ );
+};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page.tsx
new file mode 100644
index 0000000000..876f72dd84
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page.tsx
@@ -0,0 +1,5 @@
+import OAuthAppPageClient from "./page-client";
+
+export default function TokensPage() {
+ return <OAuthAppPageClient />;
+}
diff --git a/apps/web/lib/api/oauth.ts b/apps/web/lib/api/oauth.ts
index 63cf854bb1..3cc11c9656 100644
--- a/apps/web/lib/api/oauth.ts
+++ b/apps/web/lib/api/oauth.ts
@@ -1,9 +1,9 @@
export const TOKEN_LENGTH = {
clientId: 32,
- clientSecret: 40,
+ clientSecret: 32,
+ accessToken: 32,
+ refreshToken: 40,
code: 64,
- accessToken: 64,
- refreshToken: 64,
};
export const TOKEN_EXPIRY = {
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 0f991140b7..3d836f27f1 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -4,6 +4,7 @@ import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
import { Link } from "@prisma/client";
import { createLinkBodySchema } from "./zod/schemas/links";
import { tokenSchema } from "./zod/schemas/token";
+import { oAuthClientSchema } from "./zod/schemas/oauth";
export type LinkProps = Link;
@@ -194,3 +195,5 @@ export const tagColors = [
export type MetaTag = z.infer<typeof metaTagsSchema>;
export type TokenProps = z.infer<typeof tokenSchema>;
+
+export type OAuthClientProps = z.infer<typeof oAuthClientSchema>;
\ No newline at end of file
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index 9baa370080..a03fc28048 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -11,6 +11,8 @@ export const oAuthClientSchema = z.object({
.string()
.nullable()
.transform((val) => val?.split(" ") ?? []),
+ createdAt: z.date(),
+ updatedAt: z.date(),
});
export const createOAuthClientSchema = z.object({
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 3bf8e8bbe5..5473003cb4 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -368,7 +368,7 @@ model OAuthClient {
description String?
clientSecretHashed String
redirectUri String
- scopes String?
+ scopes String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectId String