Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd committed Mar 6, 2024
1 parent 30542db commit 6cb7e64
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
72 changes: 62 additions & 10 deletions front/components/workspace/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -49,6 +54,8 @@ export function EnterpriseConnectionDetails({
workspaceId: owner.sId,
});

const { strategy } = strategyDetails;

return (
<Page.Vertical gap="sm">
<Page.H variant="h5">Single Sign On</Page.H>
Expand All @@ -62,7 +69,7 @@ export function EnterpriseConnectionDetails({

setIsEnterpriseConnectionModalOpened(false);
}}
strategy={strategy}
strategyDetails={strategyDetails}
/>
<DisableEnterpriseConnectionModal
enterpriseConnectionEnabled={!!enterpriseConnection}
Expand Down Expand Up @@ -141,16 +148,16 @@ function OktaHelpLink({ hint, link }: { hint: string; link: string }) {
);
}

function CreateEnterpriseConnectionModal({
function CreateOktaEnterpriseConnectionModal({
isOpen,
onClose,
owner,
strategy,
strategyDetails,
}: {
isOpen: boolean;
onClose: (created: boolean) => void;
owner: WorkspaceType;
strategy: SupportedEnterpriseConnectionStrategies;
strategyDetails: EnterpriseConnectionStrategyDetails;
}) {
const [enterpriseConnectionDetails, setEnterpriseConnectionDetails] =
useState<{
Expand All @@ -159,6 +166,8 @@ function CreateEnterpriseConnectionModal({
domain?: string;
}>({});

const { callbackUrl } = strategyDetails;

const sendNotification = useContext(SendNotificationsContext);

const createEnterpriseConnection = async () => {
Expand All @@ -168,15 +177,15 @@ function CreateEnterpriseConnectionModal({
"Content-Type": "application/json",
},
body: JSON.stringify({
strategy,
strategy: "okta",
...enterpriseConnectionDetails,
}),
});
if (!res.ok) {
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({
Expand All @@ -187,17 +196,33 @@ function CreateEnterpriseConnectionModal({
}
};

// TODO: Make Generic!
return (
<Modal
isOpen={isOpen}
title={`Create ${strategy} Single Sign On configuration`}
title={"Create Okta Single Sign On configuration"}
onClose={() => onClose(false)}
hasChanged={false}
variant="side-sm"
>
<Page variant="modal">
<Page.Layout direction="vertical">
<Page.P>
Callback URL:
<Input
name="Callback URL"
placeholder="callback url"
value={callbackUrl}
disabled={true}
onChange={(value) =>
setEnterpriseConnectionDetails({
...enterpriseConnectionDetails,
domain: value,
})
}
className="max-w-sm"
/>
</Page.P>
<Page.Separator />
<Page.P>
Okta Domain:
<Input
Expand Down Expand Up @@ -282,6 +307,33 @@ function CreateEnterpriseConnectionModal({
);
}

function CreateEnterpriseConnectionModal({
isOpen,
onClose,
owner,
strategyDetails,
}: {
isOpen: boolean;
onClose: (created: boolean) => void;
owner: WorkspaceType;
strategyDetails: EnterpriseConnectionStrategyDetails;
}) {
switch (strategyDetails.strategy) {
case "okta":
return (
<CreateOktaEnterpriseConnectionModal
isOpen={isOpen}
onClose={onClose}
owner={owner}
strategyDetails={strategyDetails}
/>
);

default:
return <></>;
}
}

function DisableEnterpriseConnectionModal({
isOpen,
onClose,
Expand Down
2 changes: 1 addition & 1 deletion front/lib/api/config.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion front/lib/api/enterprise_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
17 changes: 16 additions & 1 deletion front/pages/w/[wId]/members/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +54,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{
user: UserType;
owner: WorkspaceType;
subscription: SubscriptionType;
enterpriseConnectionStrategyDetails: EnterpriseConnectionStrategyDetails;
plan: PlanType;
gaTrackingId: string;
workspaceHasAvailableSeats: boolean;
Expand All @@ -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,
Expand Down Expand Up @@ -110,6 +120,7 @@ export default function WorkspaceAdmin({
user,
owner,
subscription,
enterpriseConnectionStrategyDetails,
plan,
gaTrackingId,
workspaceVerifiedDomain,
Expand Down Expand Up @@ -199,7 +210,11 @@ export default function WorkspaceAdmin({
</Page.Vertical>
)}
{isDevelopmentOrDustWorkspace(owner) && (
<EnterpriseConnectionDetails owner={owner} plan={plan} />
<EnterpriseConnectionDetails
owner={owner}
plan={plan}
strategyDetails={enterpriseConnectionStrategyDetails}
/>
)}
<MemberList />
</Page.Vertical>
Expand Down

0 comments on commit 6cb7e64

Please sign in to comment.