From 6cb7e6479cf8f791a24b6174d13f09919292eb96 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Wed, 6 Mar 2024 18:33:35 +0100 Subject: [PATCH] :sparkles: --- front/components/workspace/connection.tsx | 72 +++++++++++++++++++---- front/lib/api/config.ts | 2 +- front/lib/api/enterprise_connection.ts | 2 +- front/pages/w/[wId]/members/index.tsx | 17 +++++- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/front/components/workspace/connection.tsx b/front/components/workspace/connection.tsx index f2183903b698..41dcd4d5d921 100644 --- a/front/components/workspace/connection.tsx +++ b/front/components/workspace/connection.tsx @@ -24,13 +24,18 @@ import { useWorkspaceEnterpriseConnection } from "@app/lib/swr"; interface EnterpriseConnectionDetailsProps { owner: WorkspaceType; plan: PlanType; - strategy?: SupportedEnterpriseConnectionStrategies; + strategyDetails: EnterpriseConnectionStrategyDetails; +} + +export interface EnterpriseConnectionStrategyDetails { + strategy: SupportedEnterpriseConnectionStrategies; + callbackUrl: string; } export function EnterpriseConnectionDetails({ owner, plan, - strategy = "okta", + strategyDetails, }: EnterpriseConnectionDetailsProps) { const [showNoInviteLinkPopup, setShowNoInviteLinkPopup] = useState(false); const [ @@ -49,6 +54,8 @@ export function EnterpriseConnectionDetails({ workspaceId: owner.sId, }); + const { strategy } = strategyDetails; + return ( Single Sign On @@ -62,7 +69,7 @@ export function EnterpriseConnectionDetails({ setIsEnterpriseConnectionModalOpened(false); }} - strategy={strategy} + strategyDetails={strategyDetails} /> void; owner: WorkspaceType; - strategy: SupportedEnterpriseConnectionStrategies; + strategyDetails: EnterpriseConnectionStrategyDetails; }) { const [enterpriseConnectionDetails, setEnterpriseConnectionDetails] = useState<{ @@ -159,6 +166,8 @@ function CreateEnterpriseConnectionModal({ domain?: string; }>({}); + const { callbackUrl } = strategyDetails; + const sendNotification = useContext(SendNotificationsContext); const createEnterpriseConnection = async () => { @@ -168,7 +177,7 @@ function CreateEnterpriseConnectionModal({ "Content-Type": "application/json", }, body: JSON.stringify({ - strategy, + strategy: "okta", ...enterpriseConnectionDetails, }), }); @@ -176,7 +185,7 @@ function CreateEnterpriseConnectionModal({ sendNotification({ type: "error", title: "Update failed", - description: `Failed to create ${strategy} Single Sign On configuration.`, + description: "Failed to create Okta Single Sign On configuration.", }); } else { sendNotification({ @@ -187,17 +196,33 @@ function CreateEnterpriseConnectionModal({ } }; - // TODO: Make Generic! return ( onClose(false)} hasChanged={false} variant="side-sm" > + + Callback URL: + + setEnterpriseConnectionDetails({ + ...enterpriseConnectionDetails, + domain: value, + }) + } + className="max-w-sm" + /> + + Okta Domain: void; + owner: WorkspaceType; + strategyDetails: EnterpriseConnectionStrategyDetails; +}) { + switch (strategyDetails.strategy) { + case "okta": + return ( + + ); + + default: + return <>; + } +} + function DisableEnterpriseConnectionModal({ isOpen, onClose, diff --git a/front/lib/api/config.ts b/front/lib/api/config.ts index 5da9a512826f..a829a1f02776 100644 --- a/front/lib/api/config.ts +++ b/front/lib/api/config.ts @@ -1,7 +1,7 @@ import { EnvironmentConfig } from "@dust-tt/types"; const config = { - getAuth0IssuerBaseUrl: (): string => { + getAuth0TenantUrl: (): string => { return EnvironmentConfig.getEnvVariable("AUTH0_TENANT_DOMAIN_URL"); }, getAuth0M2MClientId: (): string => { diff --git a/front/lib/api/enterprise_connection.ts b/front/lib/api/enterprise_connection.ts index b720acf58801..6580b4d272f7 100644 --- a/front/lib/api/enterprise_connection.ts +++ b/front/lib/api/enterprise_connection.ts @@ -5,7 +5,7 @@ import { ManagementClient } from "auth0"; import config from "@app/lib/api/config"; const management = new ManagementClient({ - domain: config.getAuth0IssuerBaseUrl(), + domain: config.getAuth0TenantUrl(), clientId: config.getAuth0M2MClientId(), clientSecret: config.getAuth0M2MClientSecret(), }); diff --git a/front/pages/w/[wId]/members/index.tsx b/front/pages/w/[wId]/members/index.tsx index a0c5576b36b1..ca9d2127111d 100644 --- a/front/pages/w/[wId]/members/index.tsx +++ b/front/pages/w/[wId]/members/index.tsx @@ -32,7 +32,9 @@ import { useSWRConfig } from "swr"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationAdmin } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; +import type { EnterpriseConnectionStrategyDetails } from "@app/components/workspace/connection"; import { EnterpriseConnectionDetails } from "@app/components/workspace/connection"; +import config from "@app/lib/api/config"; import { checkWorkspaceSeatAvailabilityUsingAuth, getWorkspaceVerifiedDomain, @@ -52,6 +54,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ user: UserType; owner: WorkspaceType; subscription: SubscriptionType; + enterpriseConnectionStrategyDetails: EnterpriseConnectionStrategyDetails; plan: PlanType; gaTrackingId: string; workspaceHasAvailableSeats: boolean; @@ -75,11 +78,18 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ const workspaceVerifiedDomain = await getWorkspaceVerifiedDomain(owner); const workspaceHasAvailableSeats = await checkWorkspaceSeatAvailabilityUsingAuth(auth); + + const enterpriseConnectionStrategyDetails: EnterpriseConnectionStrategyDetails = + { + strategy: "okta", + callbackUrl: config.getAuth0TenantUrl(), + }; return { props: { user, owner, subscription, + enterpriseConnectionStrategyDetails, plan, gaTrackingId: GA_TRACKING_ID, workspaceHasAvailableSeats, @@ -110,6 +120,7 @@ export default function WorkspaceAdmin({ user, owner, subscription, + enterpriseConnectionStrategyDetails, plan, gaTrackingId, workspaceVerifiedDomain, @@ -199,7 +210,11 @@ export default function WorkspaceAdmin({ )} {isDevelopmentOrDustWorkspace(owner) && ( - + )}