import { twMerge } from "tailwind-merge"; import { Button, ContentLoader, UpgradePlanModal } from "@app/components/v2"; import { OrgPermissionActions, OrgPermissionSubjects, useOrganization, useServerConfig, useSubscription } from "@app/context"; import { withPermission } from "@app/hoc"; import { usePopUp } from "@app/hooks"; import { useGetLDAPConfig, useGetOIDCConfig, useGetSSOConfig } from "@app/hooks/api"; import { LoginMethod } from "@app/hooks/api/admin/types"; import { LDAPModal } from "./LDAPModal"; import { OIDCModal } from "./OIDCModal"; import { OrgGeneralAuthSection } from "./OrgGeneralAuthSection"; import { OrgLDAPSection } from "./OrgLDAPSection"; import { OrgOIDCSection } from "./OrgOIDCSection"; import { OrgScimSection } from "./OrgSCIMSection"; import { OrgSSOSection } from "./OrgSSOSection"; import { SSOModal } from "./SSOModal"; export const OrgAuthTab = withPermission( () => { const { config: { enabledLoginMethods } } = useServerConfig(); const { currentOrg } = useOrganization(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "addLDAP", "addSSO", "addOIDC", "upgradePlan" ] as const); const { subscription } = useSubscription(); const { data: oidcConfig, isLoading: isLoadingOidcConfig } = useGetOIDCConfig( currentOrg?.slug ?? "" ); const { data: samlConfig, isLoading: isLoadingSamlConfig } = useGetSSOConfig( currentOrg?.id ?? "" ); const { data: ldapConfig, isLoading: isLdapConfig } = useGetLDAPConfig(currentOrg?.id ?? ""); const areConfigsLoading = isLoadingOidcConfig || isLoadingSamlConfig || isLdapConfig; const shouldDisplaySection = (method: LoginMethod) => !enabledLoginMethods || enabledLoginMethods.includes(method); const isOidcConfigured = oidcConfig && (oidcConfig.discoveryURL || oidcConfig.issuer); const isSamlConfigured = samlConfig && samlConfig.entryPoint; const isLdapConfigured = ldapConfig && ldapConfig.url; const shouldShowCreateIdentityProviderView = !isOidcConfigured && !isSamlConfigured && !isLdapConfigured; const createIdentityProviderView = (shouldDisplaySection(LoginMethod.SAML) || shouldDisplaySection(LoginMethod.OIDC) || shouldDisplaySection(LoginMethod.LDAP)) && ( <>

Connect an Identity Provider

Connect your identity provider to simplify user management

{shouldDisplaySection(LoginMethod.SAML) && (

SAML

)} {shouldDisplaySection(LoginMethod.OIDC) && (

OIDC

)} {shouldDisplaySection(LoginMethod.LDAP) && (

LDAP

)}
); if (areConfigsLoading) { return ; } return ( <> {shouldShowCreateIdentityProviderView ? ( createIdentityProviderView ) : ( <> {isSamlConfigured && shouldDisplaySection(LoginMethod.SAML) && (
)} {isOidcConfigured && shouldDisplaySection(LoginMethod.OIDC) && } {isLdapConfigured && shouldDisplaySection(LoginMethod.LDAP) && } )} handlePopUpToggle("upgradePlan", isOpen)} text={`You can use ${ (popUp.upgradePlan.data as { feature: string })?.feature } if you switch to Infisical's ${ (popUp.upgradePlan.data as { plan: string })?.plan } plan.`} /> ); }, { action: OrgPermissionActions.Read, subject: OrgPermissionSubjects.Sso } );