The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Made SCIM base URL + Bearer token work
Steven Tey7ba17edc8e1f
diff --git a/components/app/modals/remove-saml-modal.tsx b/components/app/modals/remove-saml-modal.tsxindex 603c588e4b..244e2fbc3e 100644--- a/components/app/modals/remove-saml-modal.tsx+++ b/components/app/modals/remove-saml-modal.tsx@@ -12,6 +12,7 @@ import { toast } from "sonner";import Button from "#/ui/button";import { Logo } from "#/ui/icons";import useSAML from "#/lib/swr/use-saml";+import { SAML_PROVIDERS } from "#/lib/constants";function RemoveSAMLModal({showRemoveSAMLModal,@@ -22,7 +23,7 @@ function RemoveSAMLModal({}) {const [removing, setRemoving] = useState(false);const { slug, logo } = useProject();- const { saml, mutate } = useSAML();+ const { saml, provider, mutate } = useSAML();return (<Modal@@ -50,16 +51,16 @@ function RemoveSAMLModal({<div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16"><div className="flex items-center space-x-3 rounded-md border border-gray-300 bg-white p-3">- <BlurImage- src="/_static/icons/okta.svg"- alt="Okta logo"- width={40}- height={40}- className="overflow-hidden rounded-full border border-gray-200"+ <img+ src={SAML_PROVIDERS.find((p) => p.name === provider)!.logo}+ alt={provider + " logo"}+ className="h-8 w-8"/><div className="flex flex-col">- <h3 className="text-sm font-medium">Okta SAML</h3>- <p className="text-xs text-gray-500">Okta SAML is configured</p>+ <h3 className="text-sm font-medium">{provider} SAML</h3>+ <p className="text-xs text-gray-500">+ {provider} SAML is configured+ </p></div></div><Button@@ -68,7 +69,7 @@ function RemoveSAMLModal({loading={removing}onClick={() => {setRemoving(true);- if (!saml?.connections[0]) {+ if (!provider) {toast.error("No SAML connection found");return;}diff --git a/components/app/modals/remove-scim-modal.tsx b/components/app/modals/remove-scim-modal.tsxnew file mode 100644index 0000000000..2e246aaef8--- /dev/null+++ b/components/app/modals/remove-scim-modal.tsx@@ -0,0 +1,119 @@+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";+import BlurImage from "#/ui/blur-image";+import Modal from "#/ui/modal";+import useProject from "#/lib/swr/use-project";+import { toast } from "sonner";+import Button from "#/ui/button";+import { Logo } from "#/ui/icons";+import useSCIM from "#/lib/swr/use-scim";++function RemoveSCIMModal({+ showRemoveSCIMModal,+ setShowRemoveSCIMModal,+}: {+ showRemoveSCIMModal: boolean;+ setShowRemoveSCIMModal: Dispatch<SetStateAction<boolean>>;+}) {+ const [removing, setRemoving] = useState(false);+ const { slug, logo } = useProject();+ const { scim, mutate } = useSCIM();++ return (+ <Modal+ showModal={showRemoveSCIMModal}+ setShowModal={setShowRemoveSCIMModal}+ >+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">+ {logo ? (+ <BlurImage+ src={logo}+ alt="Project logo"+ className="h-10 w-10 rounded-full"+ width={20}+ height={20}+ />+ ) : (+ <Logo />+ )}+ <h3 className="text-lg font-medium">Remove SCIM Directory</h3>+ <p className="text-center text-sm text-gray-500">+ This will remove the currently configured SCIM directory from your+ project. Are you sure you want to continue?+ </p>+ </div>++ <div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16">+ <div className="flex items-center space-x-3 rounded-md border border-gray-300 bg-white p-3">+ <BlurImage+ src="/_static/icons/okta.svg"+ alt="Okta logo"+ width={40}+ height={40}+ className="overflow-hidden rounded-full border border-gray-200"+ />+ <div className="flex flex-col">+ <h3 className="text-sm font-medium">Okta SCIM</h3>+ <p className="text-xs text-gray-500">Okta SCIM is configured</p>+ </div>+ </div>+ <Button+ text="Confirm remove"+ variant="danger"+ loading={removing}+ onClick={() => {+ setRemoving(true);+ if (!scim?.directories[0]) {+ toast.error("No SCIM directories found");+ return;+ }+ const { id } = scim.directories[0];+ const params = new URLSearchParams({+ directoryId: id,+ });++ fetch(`/api/projects/${slug}/scim?${params}`, {+ method: "DELETE",+ }).then(async (res) => {+ if (res.ok) {+ toast.success("SCIM directory removed successfully");+ mutate();+ setRemoving(false);+ setShowRemoveSCIMModal(false);+ } else {+ toast.error("Error removing SCIM directory");+ setRemoving(false);+ }+ });+ }}+ />+ </div>+ </Modal>+ );+}++export function useRemoveSCIMModal() {+ const [showRemoveSCIMModal, setShowRemoveSCIMModal] = useState(false);++ const RemoveSCIMModalCallback = useCallback(() => {+ return (+ <RemoveSCIMModal+ showRemoveSCIMModal={showRemoveSCIMModal}+ setShowRemoveSCIMModal={setShowRemoveSCIMModal}+ />+ );+ }, [showRemoveSCIMModal, setShowRemoveSCIMModal]);++ return useMemo(+ () => ({+ setShowRemoveSCIMModal,+ RemoveSCIMModal: RemoveSCIMModalCallback,+ }),+ [setShowRemoveSCIMModal, RemoveSCIMModalCallback],+ );+}diff --git a/components/app/modals/saml-modal.tsx b/components/app/modals/saml-modal.tsxindex ef3ad947dd..66eda35b88 100644--- a/components/app/modals/saml-modal.tsx+++ b/components/app/modals/saml-modal.tsx@@ -8,7 +8,7 @@ import {import Modal from "#/ui/modal";import Button from "#/ui/button";import { toast } from "sonner";-import { ArrowRight } from "lucide-react";+import { ArrowRight, Lock } from "lucide-react";import { Logo } from "#/ui/icons";import useProject from "#/lib/swr/use-project";import { InfoTooltip, SimpleTooltipContent } from "#/ui/tooltip";@@ -29,18 +29,12 @@ function SAMLModal({return (<Modal showModal={showSAMLModal} setShowModal={setShowSAMLModal}><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-8 sm:px-16">- <div className="flex items-center space-x-3 py-4">- <img- src="/_static/icons/okta.svg"- alt="Okta logo"- className="h-10 w-10"- />- <ArrowRight className="h-5 w-5 text-gray-600" />- <Logo />+ <div className="rounded-full border border-gray-200 p-2">+ <Lock className="h-4 w-4 text-gray-600" /></div>- <h3 className="text-lg font-medium">Okta SAML</h3>+ <h3 className="text-lg font-medium">Configure SAML</h3><p className="text-center text-sm text-gray-500">- Configure Okta SAML for your Dub account.+ Configure SAML for your Dub account.</p></div>@@ -57,13 +51,14 @@ function SAMLModal({body: JSON.stringify({metadataUrl: e.currentTarget.metadataUrl.value,}),- }).then((res) => {+ }).then(async (res) => {if (res.ok) {mutate();toast.success("Successfully configured SAML");setShowSAMLModal(false);} else {- toast.error("Failed to configure SAML");+ const err = await res.text();+ toast.error(err);}setSubmitting(false);});@@ -71,7 +66,7 @@ function SAMLModal({className="flex flex-col space-y-4"><div>- <div className="flex items-center space-x-2">+ <div className="flex items-center space-x-1"><h2 className="text-sm font-medium text-gray-900">Metadata URL</h2>@@ -96,7 +91,7 @@ function SAMLModal({className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"/></div>- <Button text="Submit" loading={submitting} />+ <Button text="Save changes" loading={submitting} /></form></div></Modal>diff --git a/components/app/modals/scim-modal.tsx b/components/app/modals/scim-modal.tsxnew file mode 100644index 0000000000..5a2d6ff74e--- /dev/null+++ b/components/app/modals/scim-modal.tsx@@ -0,0 +1,260 @@+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useRef,+ useState,+} from "react";+import Modal from "#/ui/modal";+import Button from "#/ui/button";+import { toast } from "sonner";+import { Eye, EyeOff, FolderSync, RefreshCcw } from "lucide-react";+import { Logo } from "#/ui/icons";+import useProject from "#/lib/swr/use-project";+import { InfoTooltip, SimpleTooltipContent } from "#/ui/tooltip";+import { HOME_DOMAIN, SAML_PROVIDERS } from "#/lib/constants";+import useSCIM from "#/lib/swr/use-scim";+import { SAMLProviderProps } from "#/lib/types";+import { Copy, Tick } from "@/components/shared/icons";++function SCIMModal({+ showSCIMModal,+ setShowSCIMModal,+}: {+ showSCIMModal: boolean;+ setShowSCIMModal: Dispatch<SetStateAction<boolean>>;+}) {+ const { slug } = useProject();+ const [submitting, setSubmitting] = useState(false);+ const { scim, provider, configured, mutate } = useSCIM();+ const [selectedProvider, setSelectedProvider] = useState(+ provider || "okta-scim-v2",+ );+ const [copiedBaseUrl, setCopiedBaseUrl] = useState(false);+ const [showBearerToken, setShowBearerToken] = useState(false);+ const [copiedBearerToken, setCopiedBearerToken] = useState(false);++ return (+ <Modal showModal={showSCIMModal} setShowModal={setShowSCIMModal}>+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-8 sm:px-16">+ {configured ? (+ <div className="flex items-center space-x-3 py-4">+ <img+ src={SAML_PROVIDERS.find((p) => p.scim === provider)!.logo}+ alt={`${provider} logo`}+ className="h-10 w-10"+ />+ <RefreshCcw className="h-5 w-5 text-gray-600" />+ <Logo />+ </div>+ ) : (+ <div className="rounded-full border border-gray-200 p-3">+ <FolderSync className="h-5 w-5 text-gray-600" />+ </div>+ )}++ <h3 className="text-lg font-medium">+ {configured+ ? `${SAML_PROVIDERS.find((p) => p.scim === provider)!.name} SCIM`+ : "Configure Directory Sync"}+ </h3>+ <p className="text-center text-sm text-gray-500">+ {configured+ ? "Your project is currently syncing with your SCIM directory."+ : "Select a provider to configure directory sync for your Dub project."}+ </p>+ </div>++ <div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16">+ <form+ onSubmit={async (e) => {+ e.preventDefault();+ setSubmitting(true);+ fetch(`/api/projects/${slug}/scim`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ provider: e.currentTarget.provider.value,+ ...(configured && {+ currentDirectoryId: scim.directories[0].id,+ }),+ }),+ }).then(async (res) => {+ if (res.ok) {+ mutate();+ toast.success("Successfully configured SCIM");+ } else {+ const err = await res.text();+ toast.error(err);+ }+ setSubmitting(false);+ });+ }}+ className="flex flex-col space-y-4"+ >+ <div>+ <div className="flex items-center space-x-1">+ <h2 className="text-sm font-medium text-gray-900">+ Directory Provider+ </h2>+ <InfoTooltip+ content={+ <SimpleTooltipContent+ title="Your directory provider is the IDP you use to manage your users."+ cta="Read the guide."+ href={`${HOME_DOMAIN}/help/article/configuring-scim`}+ />+ }+ />+ </div>+ <select+ id="provider"+ name="provider"+ required+ value={selectedProvider}+ onChange={(e) =>+ setSelectedProvider(e.target.value as SAMLProviderProps["scim"])+ }+ className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"+ >+ {SAML_PROVIDERS.map((provider) => (+ <option key={provider.scim} value={provider.scim}>+ {provider.name}+ </option>+ ))}+ </select>+ </div>++ {configured && (+ <>+ <div className="w-full border-t border-gray-200" />+ <div>+ <div className="flex items-center space-x-1">+ <h2 className="text-sm font-medium text-gray-900">+ SCIM 2.0 Base URL+ </h2>+ <InfoTooltip+ content={+ <SimpleTooltipContent+ title="Your directory provider is the IDP you use to manage your users."+ cta="Read the guide."+ href={`${HOME_DOMAIN}/help/article/configuring-scim`}+ />+ }+ />+ </div>+ <div className="mt-1 flex w-full items-center justify-between rounded-md border border-gray-300 bg-white px-3 py-2 shadow-sm">+ <div className="overflow-auto scrollbar-hide">+ <p className="whitespace-nowrap text-gray-600 sm:text-sm">{`${scim.directories[0].webhook.endpoint}/${scim.directories[0].id}`}</p>+ </div>+ <button+ type="button"+ className="pl-2"+ onClick={() => {+ navigator.clipboard.writeText(+ `${scim.directories[0].webhook.endpoint}/${scim.directories[0].id}`,+ );+ setCopiedBaseUrl(true);+ toast.success("Copied to clipboard");+ setTimeout(() => setCopiedBaseUrl(false), 3000);+ }}+ >+ {copiedBaseUrl ? (+ <Tick className="h-4 w-4 text-gray-500" />+ ) : (+ <Copy className="h-4 w-4 text-gray-500" />+ )}+ </button>+ </div>+ </div>++ <div>+ <div className="flex items-center space-x-1">+ <h2 className="text-sm font-medium text-gray-900">+ OAuth Bearer Token+ </h2>+ <InfoTooltip+ content={+ <SimpleTooltipContent+ title="Your directory provider is the IDP you use to manage your users."+ cta="Read the guide."+ href={`${HOME_DOMAIN}/help/article/configuring-scim`}+ />+ }+ />+ </div>+ <div className="mt-1 flex w-full items-center justify-between rounded-md border border-gray-300 bg-white px-3 py-2 shadow-sm">+ <input+ type={showBearerToken ? "text" : "password"}+ contentEditable={false}+ className="border-none p-0 focus:outline-none focus:ring-0 sm:text-sm"+ value={`${scim.directories[0].scim.secret}`}+ />+ <div className="flex space-x-2 pl-2">+ <button+ type="button"+ onClick={() => {+ navigator.clipboard.writeText(+ `${scim.directories[0].scim.secret}`,+ );+ setCopiedBearerToken(true);+ toast.success("Copied to clipboard");+ setTimeout(() => setCopiedBearerToken(false), 3000);+ }}+ >+ {copiedBearerToken ? (+ <Tick className="h-4 w-4 text-gray-500" />+ ) : (+ <Copy className="h-4 w-4 text-gray-500" />+ )}+ </button>++ <button+ type="button"+ onClick={() => setShowBearerToken(!showBearerToken)}+ >+ {showBearerToken ? (+ <Eye className="h-4 w-4 text-gray-500" />+ ) : (+ <EyeOff className="h-4 w-4 text-gray-500" />+ )}+ </button>+ </div>+ </div>+ </div>+ </>+ )}+ <Button+ text="Save changes"+ loading={submitting}+ disabled={selectedProvider === provider}+ />+ </form>+ </div>+ </Modal>+ );+}++export function useSCIMModal() {+ const [showSCIMModal, setShowSCIMModal] = useState(false);++ const SCIMModalCallback = useCallback(() => {+ return (+ <SCIMModal+ showSCIMModal={showSCIMModal}+ setShowSCIMModal={setShowSCIMModal}+ />+ );+ }, [showSCIMModal, setShowSCIMModal]);++ return useMemo(+ () => ({+ setShowSCIMModal,+ SCIMModal: SCIMModalCallback,+ }),+ [setShowSCIMModal, SCIMModalCallback],+ );+}diff --git a/components/layout/app/settings-layout.tsx b/components/layout/app/settings-layout.tsxindex d49f154945..9c81ec07ad 100644--- a/components/layout/app/settings-layout.tsx+++ b/components/layout/app/settings-layout.tsx@@ -44,7 +44,7 @@ export default function SettingsLayout({ children }: { children: ReactNode }) {</MaxWidthWrapper></div><MaxWidthWrapper className="grid items-start gap-5 py-10 md:grid-cols-5">- <div className="flex gap-1 md:grid">+ <div className="sticky top-36 flex gap-1 md:grid">{tabs.map(({ name, href }) => (<Linkhref={href}diff --git a/lib/constants/index.ts b/lib/constants/index.tsindex 857c14b412..7142b921d1 100644--- a/lib/constants/index.ts+++ b/lib/constants/index.ts@@ -60,6 +60,13 @@ export const APP_DOMAIN =? "https://preview.dub.sh": "http://localhost:8888";+export const APP_DOMAIN_WITH_NGROK =+ process.env.NEXT_PUBLIC_VERCEL_ENV === "production"+ ? "https://app.dub.sh"+ : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"+ ? "https://preview.dub.sh"+ : process.env.NGROK_URL;+export const DEFAULT_REDIRECTS = {home: "https://dub.sh",dub: "https://dub.sh",@@ -149,3 +156,21 @@ export const DEFAULT_LINK_PROPS = {};export const DUB_PROJECT_ID = "cl7pj5kq4006835rbjlt2ofka";++export const SAML_PROVIDERS = [+ {+ name: "Okta",+ logo: "/_static/icons/okta.svg",+ scim: "okta-scim-v2",+ },+ {+ name: "Azure AD",+ logo: "/_static/icons/azure.svg",+ scim: "azure-scim-v2",+ },+ {+ name: "Google Workspace",+ logo: "/_static/icons/google.svg",+ scim: "google",+ },+];diff --git a/lib/jackson.ts b/lib/jackson.tsindex cc2d45244f..3b283cfc6c 100644--- a/lib/jackson.ts+++ b/lib/jackson.ts@@ -4,6 +4,7 @@ import type {IOAuthController,JacksonOption,ISPSAMLConfig,+ IDirectorySyncController,} from "@boxyhq/saml-jackson";const samlPath = "/api/auth/saml/callback";@@ -21,7 +22,8 @@ const opts: JacksonOption = {rejectUnauthorized: false,},},- idpEnabled: true,+ idpEnabled: true, // to allow folks to SSO directly from their IDP+ scimPath: "/api/scim/v2.0", // custom SCIM endpointclientSecretVerifier: process.env.NEXTAUTH_SECRET as string,};@@ -30,6 +32,7 @@ declare global {var apiController: IConnectionAPIController | undefined;var oauthController: IOAuthController | undefined;var samlSPConfig: ISPSAMLConfig | undefined;+ var directorySyncController: IDirectorySyncController | undefined;}export default async function init() {@@ -38,14 +41,14 @@ export default async function init() {!globalThis.apiController ||!globalThis.oauthController ||!globalThis.samlSPConfig ||- !globalThis.directorySync+ !globalThis.directorySyncController) {const ret = await jackson(opts);globalThis.connectionController = ret.connectionAPIController;globalThis.apiController = ret.connectionAPIController;globalThis.oauthController = ret.oauthController;globalThis.samlSPConfig = ret.spConfig;- globalThis.directorySync = ret.directorySyncController;+ globalThis.directorySyncController = ret.directorySyncController;}return {@@ -53,6 +56,6 @@ export default async function init() {apiController: globalThis.apiController,oauthController: globalThis.oauthController,samlSPConfig: globalThis.samlSPConfig,- directorySync: global.directorySyncController,+ directorySyncController: globalThis.directorySyncController,};}diff --git a/lib/swr/use-saml.ts b/lib/swr/use-saml.tsindex 37fa476264..1f1f21cb66 100644--- a/lib/swr/use-saml.ts+++ b/lib/swr/use-saml.ts@@ -2,6 +2,7 @@ import { useRouter } from "next/router";import useSWR from "swr";import type { SAMLSSORecord } from "@boxyhq/saml-jackson";import { fetcher } from "#/lib/utils";+import { useMemo } from "react";export default function useSAML() {const router = useRouter();@@ -9,18 +10,25 @@ export default function useSAML() {slug: string;};- const {- data: saml,- isLoading,- mutate,- } = useSWR<{ connections: SAMLSSORecord[] }>(+ const { data, isLoading, mutate } = useSWR<{ connections: SAMLSSORecord[] }>(slug && `/api/projects/${slug}/saml`,fetcher,+ {+ keepPreviousData: true,+ },);+ const configured = useMemo(() => {+ return data?.connections && data.connections.length > 0;+ }, [data]);+return {- saml,- isLoading,+ saml: data as { connections: SAMLSSORecord[] },+ provider: configured+ ? data!.connections[0].idpMetadata.friendlyProviderName+ : null,+ configured,+ loading: !slug || isLoading,mutate,};}diff --git a/lib/swr/use-scim.ts b/lib/swr/use-scim.tsnew file mode 100644index 0000000000..0b103091cf--- /dev/null+++ b/lib/swr/use-scim.ts@@ -0,0 +1,32 @@+import { useRouter } from "next/router";+import useSWR from "swr";+import type { Directory } from "@boxyhq/saml-jackson";+import { fetcher } from "#/lib/utils";+import { useMemo } from "react";++export default function useSCIM() {+ const router = useRouter();+ const { slug } = router.query as {+ slug: string;+ };++ const { data, isLoading, mutate } = useSWR<{ directories: Directory[] }>(+ slug && `/api/projects/${slug}/scim`,+ fetcher,+ {+ keepPreviousData: true,+ },+ );++ const configured = useMemo(() => {+ return data?.directories && data.directories.length > 0;+ }, [data]);++ return {+ scim: data as { directories: Directory[] },+ provider: configured ? data!.directories[0].type : null,+ configured,+ loading: !slug || isLoading,+ mutate,+ };+}diff --git a/lib/types.ts b/lib/types.tsindex 3a6aa7ff25..777cb4361e 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -1,3 +1,5 @@+import { DirectorySyncProviders } from "@boxyhq/saml-jackson";+export interface SimpleLinkProps {domain?: string;key: string;@@ -113,3 +115,9 @@ export interface ShortioDomainProps {domain: string;links: number;}++export interface SAMLProviderProps {+ name: string;+ logo: string;+ scim: keyof typeof DirectorySyncProviders;+}diff --git a/pages/api/projects/[slug]/import/bitly.ts b/pages/api/projects/[slug]/import/bitly.tsindex 1dc49715ea..746de8a62c 100644--- a/pages/api/projects/[slug]/import/bitly.ts+++ b/pages/api/projects/[slug]/import/bitly.ts@@ -1,5 +1,6 @@import { addDomainToVercel } from "#/lib/api/domains";import { withProjectAuth } from "#/lib/auth";+import { APP_DOMAIN_WITH_NGROK } from "#/lib/constants";import { qstash } from "#/lib/cron/utils";import prisma from "#/lib/prisma";import { BitlyGroupProps } from "#/lib/types";@@ -93,20 +94,13 @@ export default withProjectAuth(async (req, res, project) => {return result;}, []);- const hostname =- process.env.NEXT_PUBLIC_VERCEL_ENV === "production"- ? "https://app.dub.sh"- : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"- ? "https://preview.dub.sh"- : process.env.NGROK_URL;-const response = await Promise.all(groups// only add groups that have at least 1 domain selected for import.filter(({ domains }) => domains.length > 0).map(({ bitlyGroup, domains, keepTags }) =>qstash.publishJSON({- url: `${hostname}/api/cron/import/bitly`,+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/bitly`,body: {projectId: project.id,bitlyGroup,diff --git a/pages/api/projects/[slug]/import/short.ts b/pages/api/projects/[slug]/import/short.tsindex bec10e133d..d155eebfcc 100644--- a/pages/api/projects/[slug]/import/short.ts+++ b/pages/api/projects/[slug]/import/short.ts@@ -1,5 +1,6 @@import { addDomainToVercel } from "#/lib/api/domains";import { withProjectAuth } from "#/lib/auth";+import { APP_DOMAIN_WITH_NGROK } from "#/lib/constants";import { qstash } from "#/lib/cron/utils";import prisma from "#/lib/prisma";import { ShortioDomainProps } from "#/lib/types";@@ -82,17 +83,10 @@ export default withProjectAuth(async (req, res, project) => {]);}- const hostname =- process.env.NEXT_PUBLIC_VERCEL_ENV === "production"- ? "https://app.dub.sh"- : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"- ? "https://preview.dub.sh"- : process.env.NGROK_URL;-const response = await Promise.all(selectedDomains.map(({ id, domain }) =>qstash.publishJSON({- url: `${hostname}/api/cron/import/short`,+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/short`,body: {projectId: project.id,domainId: id,diff --git a/pages/api/projects/[slug]/saml.ts b/pages/api/projects/[slug]/saml.tsindex 4b4e8a5366..22066fac30 100644--- a/pages/api/projects/[slug]/saml.ts+++ b/pages/api/projects/[slug]/saml.ts@@ -1,58 +1,63 @@import { withProjectAuth } from "#/lib/auth";import jackson from "#/lib/jackson";-export default withProjectAuth(async (req, res, project) => {- // GET /api/projects/[slug]/saml – get all SAML connections- if (req.method === "GET") {- const { apiController } = await jackson();-- const connections = await apiController.getConnections({- tenant: project.id,- product: "Dub",- });-- const response = {- connections,- issuer: "https://saml.dub.sh",- acs: `${process.env.NEXTAUTH_URL}/api/auth/saml/callback`,- };-- return res.status(200).json(response);-- // POST /api/projects/[slug]/saml – create a new SAML connection- } else if (req.method === "POST") {- const { metadataUrl } = req.body;-- const { apiController } = await jackson();-- const data = await apiController.createSAMLConnection({- encodedRawMetadata: "",- metadataUrl,- defaultRedirectUrl: `${process.env.NEXTAUTH_URL}/auth/saml`,- redirectUrl: process.env.NEXTAUTH_URL as string,- tenant: project.id,- product: "Dub",- });-- return res.status(200).json(data);-- // DELETE /api/projects/[slug]/saml – delete all SAML connections- } else if (req.method === "DELETE") {- const { clientID, clientSecret } = req.query as {- clientID: string;- clientSecret: string;- };-- const { apiController } = await jackson();-- const response = await apiController.deleteConnections({- clientID,- clientSecret,- });-- return res.status(200).json(response);- } else {- res.setHeader("Allow", ["GET", "POST", "DELETE"]);- return res.status(405).end(`Method ${req.method} Not Allowed`);- }-});+export default withProjectAuth(+ async (req, res, project) => {+ // GET /api/projects/[slug]/saml – get all SAML connections+ if (req.method === "GET") {+ const { apiController } = await jackson();++ const connections = await apiController.getConnections({+ tenant: project.id,+ product: "Dub",+ });++ const response = {+ connections,+ issuer: "https://saml.dub.sh",+ acs: `${process.env.NEXTAUTH_URL}/api/auth/saml/callback`,+ };++ return res.status(200).json(response);++ // POST /api/projects/[slug]/saml – create a new SAML connection+ } else if (req.method === "POST") {+ const { metadataUrl } = req.body;++ const { apiController } = await jackson();++ const data = await apiController.createSAMLConnection({+ encodedRawMetadata: "",+ metadataUrl,+ defaultRedirectUrl: `${process.env.NEXTAUTH_URL}/auth/saml`,+ redirectUrl: process.env.NEXTAUTH_URL as string,+ tenant: project.id,+ product: "Dub",+ });++ return res.status(200).json(data);++ // DELETE /api/projects/[slug]/saml – delete all SAML connections+ } else if (req.method === "DELETE") {+ const { clientID, clientSecret } = req.query as {+ clientID: string;+ clientSecret: string;+ };++ const { apiController } = await jackson();++ const response = await apiController.deleteConnections({+ clientID,+ clientSecret,+ });++ return res.status(200).json(response);+ } else {+ res.setHeader("Allow", ["GET", "POST", "DELETE"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+ },+ {+ requiredPlan: ["enterprise"],+ },+);diff --git a/pages/api/projects/[slug]/scim.ts b/pages/api/projects/[slug]/scim.tsindex e69de29bb2..6accc3cbd5 100644--- a/pages/api/projects/[slug]/scim.ts+++ b/pages/api/projects/[slug]/scim.ts@@ -0,0 +1,70 @@+import { withProjectAuth } from "#/lib/auth";+import { APP_DOMAIN_WITH_NGROK } from "#/lib/constants";+import jackson from "#/lib/jackson";+import { SAMLProviderProps } from "#/lib/types";++export default withProjectAuth(+ async (req, res, project) => {+ const { directorySyncController } = await jackson();++ // GET /api/projects/[slug]/scim – get all SCIM directories+ if (req.method === "GET") {+ const { data, error } =+ await directorySyncController.directories.getByTenantAndProduct(+ project.id,+ "Dub",+ );+ if (error) {+ return res.status(500).end(error.message);+ }++ return res.status(200).json({+ directories: data,+ });++ // POST /api/projects/[slug]/scim – create a new SCIM directory+ } else if (req.method === "POST") {+ const { provider = "okta-scim-v2", currentDirectoryId } = req.body as {+ provider: SAMLProviderProps["scim"];+ currentDirectoryId?: string;+ };++ const [data, _] = await Promise.all([+ directorySyncController.directories.create({+ name: "Dub SCIM Directory",+ tenant: project.id,+ product: "Dub",+ type: provider,+ webhook_url: `${APP_DOMAIN_WITH_NGROK}/api/scim/v2.0`,+ webhook_secret: process.env.NEXTAUTH_SECRET as string,+ }),+ currentDirectoryId &&+ directorySyncController.directories.delete(currentDirectoryId),+ ]);++ return res.status(200).json(data);++ // DELETE /api/projects/[slug]/scim – delete a SCIM directory+ } else if (req.method === "DELETE") {+ const { directoryId } = req.query as {+ directoryId?: string;+ };++ if (!directoryId) {+ return res.status(400).end(`Missing SCIM directory ID`);+ }++ const response = await directorySyncController.directories.delete(+ directoryId,+ );++ return res.status(200).json(response);+ } else {+ res.setHeader("Allow", ["GET", "POST", "DELETE"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+ },+ {+ requiredPlan: ["enterprise"],+ },+);diff --git a/pages/api/scim/[...directory].ts b/pages/api/scim/v2.0/[...directory].tssimilarity index 95%rename from pages/api/scim/[...directory].tsrename to pages/api/scim/v2.0/[...directory].tsindex 73e0082f3f..6e9b5c248f 100644--- a/pages/api/scim/[...directory].ts+++ b/pages/api/scim/v2.0/[...directory].ts@@ -17,7 +17,7 @@ export default async function handler(req: NextApiRequest,res: NextApiResponse,) {- const { directorySync } = await jackson();+ const { directorySyncController } = await jackson();const { method, query, body } = req;@@ -41,7 +41,7 @@ export default async function handler(},};- const { status, data } = await directorySync.requests.handle(+ const { status, data } = await directorySyncController.requests.handle(request,handleEvents,);diff --git a/pages/app/[slug]/settings/security.tsx b/pages/app/[slug]/settings/security.tsxindex c8c020789e..16499936cd 100644--- a/pages/app/[slug]/settings/security.tsx+++ b/pages/app/[slug]/settings/security.tsx@@ -1,40 +1,50 @@+import { useRouter } from "next/router";import Button from "#/ui/button";import { useSAMLModal } from "@/components/app/modals/saml-modal";import { useRemoveSAMLModal } from "@/components/app/modals/remove-saml-modal";import SettingsLayout from "@/components/layout/app/settings-layout";-import { Lock, ShieldOff } from "lucide-react";-import useProject from "#/lib/swr/use-project";+import { FolderSync, Lock, ShieldOff } from "lucide-react";import { useMemo, useState } from "react";import { ThreeDots } from "@/components/shared/icons";import Popover from "#/ui/popover";import IconMenu from "@/components/shared/icon-menu";import useSAML from "#/lib/swr/use-saml";+import useSCIM from "#/lib/swr/use-scim";+import { useRemoveSCIMModal } from "@/components/app/modals/remove-scim-modal";+import { useSCIMModal } from "@/components/app/modals/scim-modal";+import { SAML_PROVIDERS } from "#/lib/constants";export default function ProjectSecurity() {+ return (+ <SettingsLayout>+ <SAMLSection />+ <SCIMSection />+ </SettingsLayout>+ );+}++const SAMLSection = () => {const { SAMLModal, setShowSAMLModal } = useSAMLModal();const { RemoveSAMLModal, setShowRemoveSAMLModal } = useRemoveSAMLModal();- const { slug } = useProject();- const { saml, isLoading } = useSAML();+ const { provider, configured, loading } = useSAML();const data = useMemo(() => {- if (!slug || isLoading) {+ if (loading) {return {- status: "loading",logo: null,title: null,description: null,};- } else if (saml && saml.connections.length > 0) {+ } else if (configured) {return {- status: "configured",logo: (<img- src="/_static/icons/okta.svg"- alt={saml.connections[0].idpMetadata.friendlyProviderName + " logo"}+ src={SAML_PROVIDERS.find((p) => p.name === provider)!.logo}+ alt={provider + " logo"}className="h-8 w-8"/>),- title: `${saml.connections[0].idpMetadata.friendlyProviderName} SAML`,+ title: `${provider} SAML`,description: "SAML SSO is configured for your project.",};} else@@ -48,14 +58,13 @@ export default function ProjectSecurity() {title: "SAML",description: "Choose an identity provider to get started.",};- }, [isLoading, saml]);+ }, [provider, configured, loading]);const [openPopover, setOpenPopover] = useState(false);return (- <SettingsLayout>- {data.status === "unconfigured" && <SAMLModal />}- {data.status === "configured" && <RemoveSAMLModal />}+ <>+ {configured ? <RemoveSAMLModal /> : <SAMLModal />}<div className="rounded-lg border border-gray-200 bg-white"><div className="relative flex flex-col space-y-6 p-5 sm:p-10"><div className="flex flex-col space-y-3">@@ -78,18 +87,16 @@ export default function ProjectSecurity() {<div className="h-5 w-20 animate-pulse rounded-md bg-gray-100" />)}{data.description ? (- <p className="text-sm text-gray-500">- Choose an identity provider to get started.- </p>+ <p className="text-sm text-gray-500">{data.description}</p>) : (<div className="mt-2 h-4 w-40 animate-pulse rounded-md bg-gray-100" />)}</div></div><div>- {data.status === "loading" ? (+ {loading ? (<div className="h-9 w-24 animate-pulse rounded-md bg-gray-100" />- ) : data.status === "configured" ? (+ ) : configured ? (<Popovercontent={<div className="grid w-full gap-1 p-2 sm:w-48">@@ -137,6 +144,144 @@ export default function ProjectSecurity() {<p className="text-sm text-gray-500">Learn more about SAML SSO</p></div></div>- </SettingsLayout>+ </>);-}+};++const SCIMSection = () => {+ const { SCIMModal, setShowSCIMModal } = useSCIMModal();+ const { RemoveSCIMModal, setShowRemoveSCIMModal } = useRemoveSCIMModal();++ const { provider, configured, loading } = useSCIM();++ const data = useMemo(() => {+ if (loading) {+ return {+ logo: null,+ title: null,+ description: null,+ };+ } else if (configured) {+ return {+ logo: (+ <img+ src={SAML_PROVIDERS.find((p) => p.scim === provider)!.logo}+ alt={`${provider} logo`}+ className="h-8 w-8"+ />+ ),+ title: `${SAML_PROVIDERS.find((p) => p.scim === provider)!.name} SCIM`,+ description: "SCIM directory sync is configured for your project.",+ };+ } else+ return {+ logo: (+ <div className="rounded-full border border-gray-200 p-2">+ <FolderSync className="h-4 w-4 text-gray-600" />+ </div>+ ),+ title: "SCIM",+ description: "Choose an identity provider to get started.",+ };+ }, [provider, configured, loading]);++ const [openPopover, setOpenPopover] = useState(false);++ return (+ <>+ <SCIMModal />+ {configured && <RemoveSCIMModal />}+ <div className="rounded-lg border border-gray-200 bg-white">+ <div className="relative flex flex-col space-y-6 p-5 sm:p-10">+ <div className="flex flex-col space-y-3">+ <h2 className="text-xl font-medium">Directory Sync</h2>+ <p className="text-sm text-gray-500">+ Automatically provision and deprovision users from your identity+ provider.+ </p>+ </div>++ <div className="mt-2 flex items-center justify-between rounded-md border border-gray-200 px-4 py-3">+ <div className="flex items-center space-x-4">+ {data.logo || (+ <div className="h-8 w-8 animate-pulse rounded-full bg-gray-100" />+ )}+ <div className="flex flex-col">+ {data.title ? (+ <h3 className="font-medium">{data.title}</h3>+ ) : (+ <div className="h-5 w-20 animate-pulse rounded-md bg-gray-100" />+ )}+ {data.description ? (+ <p className="text-sm text-gray-500">{data.description}</p>+ ) : (+ <div className="mt-2 h-4 w-40 animate-pulse rounded-md bg-gray-100" />+ )}+ </div>+ </div>+ <div>+ {loading ? (+ <div className="h-9 w-24 animate-pulse rounded-md bg-gray-100" />+ ) : configured ? (+ <Popover+ content={+ <div className="grid w-full gap-1 p-2 sm:w-48">+ <button+ onClick={() => {+ setShowSCIMModal(true);+ setOpenPopover(false);+ }}+ className="rounded-md p-2 text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"+ >+ <IconMenu+ text="View configuration"+ icon={<FolderSync className="h-4 w-4" />}+ />+ </button>+ <button+ onClick={() => {+ setShowRemoveSCIMModal(true);+ setOpenPopover(false);+ }}+ className="rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"+ >+ <IconMenu+ text="Remove"+ icon={<ShieldOff className="h-4 w-4" />}+ />+ </button>+ </div>+ }+ align="end"+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ >+ <button+ type="button"+ onClick={(e) => {+ e.stopPropagation();+ setOpenPopover(!openPopover);+ }}+ className="rounded-md px-1 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"+ >+ <span className="sr-only">Edit</span>+ <ThreeDots className="h-5 w-5 text-gray-500" />+ </button>+ </Popover>+ ) : (+ <Button+ text="Configure"+ onClick={() => setShowSCIMModal(true)}+ />+ )}+ </div>+ </div>+ </div>++ <div className="flex items-center justify-between rounded-b-lg border-t border-gray-200 bg-gray-50 px-3 py-5 sm:px-10">+ <p className="text-sm text-gray-500">Learn more about SAML SSO</p>+ </div>+ </div>+ </>+ );+};diff --git a/public/_static/icons/azure.svg b/public/_static/icons/azure.svgnew file mode 100644index 0000000000..5334aa7ca6--- /dev/null+++ b/public/_static/icons/azure.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 23"><path fill="#f3f3f3" d="M0 0h23v23H0z"/><path fill="#f35325" d="M1 1h10v10H1z"/><path fill="#81bc06" d="M12 1h10v10H12z"/><path fill="#05a6f0" d="M1 12h10v10H1z"/><path fill="#ffba08" d="M12 12h10v10H12z"/></svg>\ No newline at end of filediff --git a/public/_static/icons/google.svg b/public/_static/icons/google.svgnew file mode 100644index 0000000000..4cf163bfe2--- /dev/null+++ b/public/_static/icons/google.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="705.6" height="720" viewBox="0 0 186.69 190.5" xmlns:v="https://vecta.io/nano"><g transform="translate(1184.583 765.171)"><path clip-path="none" mask="none" d="M-1089.333-687.239v36.888h51.262c-2.251 11.863-9.006 21.908-19.137 28.662l30.913 23.986c18.011-16.625 28.402-41.044 28.402-70.052 0-6.754-.606-13.249-1.732-19.483z" fill="#4285f4"/><path clip-path="none" mask="none" d="M-1142.714-651.791l-6.972 5.337-24.679 19.223h0c15.673 31.086 47.796 52.561 85.03 52.561 25.717 0 47.278-8.486 63.038-23.033l-30.913-23.986c-8.486 5.715-19.31 9.179-32.125 9.179-24.765 0-45.806-16.712-53.34-39.226z" fill="#34a853"/><path clip-path="none" mask="none" d="M-1174.365-712.61c-6.494 12.815-10.217 27.276-10.217 42.689s3.723 29.874 10.217 42.689c0 .086 31.693-24.592 31.693-24.592-1.905-5.715-3.031-11.776-3.031-18.098s1.126-12.383 3.031-18.098z" fill="#fbbc05"/><path d="M-1089.333-727.244c14.028 0 26.497 4.849 36.455 14.201l27.276-27.276c-16.539-15.413-38.013-24.852-63.731-24.852-37.234 0-69.359 21.388-85.032 52.561l31.692 24.592c7.533-22.514 28.575-39.226 53.34-39.226z" fill="#ea4335" clip-path="none" mask="none"/></g></svg>\ No newline at end of file