import { twMerge } from "tailwind-merge"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { Button, ContentLoader, EmptyState } 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 { OrgSSOSection } from "./OrgSSOSection"; import { SSOModal } from "./SSOModal"; export const OrgSsoTab = 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, isPending: isLoadingOidcConfig } = useGetOIDCConfig( currentOrg?.id ?? "" ); const { data: samlConfig, isPending: isLoadingSamlConfig } = useGetSSOConfig( currentOrg?.id ?? "" ); const { data: ldapConfig, isPending: isLoadingLdapConfig } = useGetLDAPConfig( currentOrg?.id ?? "" ); const areConfigsLoading = isLoadingOidcConfig || isLoadingSamlConfig || isLoadingLdapConfig; const shouldDisplaySection = (method: LoginMethod[] | LoginMethod) => { if (Array.isArray(method)) { return method.some((m) => !enabledLoginMethods || enabledLoginMethods.includes(m)); } return !enabledLoginMethods || enabledLoginMethods.includes(method); }; const isOidcConfigured = Boolean(oidcConfig && (oidcConfig.discoveryURL || oidcConfig.issuer)); const isSamlConfigured = samlConfig && (samlConfig.entryPoint || samlConfig.issuer || samlConfig.cert); const isLdapConfigured = ldapConfig && ldapConfig.url; const isGoogleConfigured = shouldDisplaySection(LoginMethod.GOOGLE); 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 with options like SAML, OIDC, and LDAP.

{shouldDisplaySection(LoginMethod.SAML) && (

SAML

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

OIDC

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

LDAP

)}
) : (

Single Sign-On (SSO) has been disabled

Contact your server administrator

); if (areConfigsLoading) { return ; } return ( <>
{shouldDisplaySection([LoginMethod.SAML, LoginMethod.GOOGLE]) && ( )} {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 } );