import { twMerge } from "tailwind-merge"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { Button, ContentLoader } 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 { OrgGenericAuthSection } from "./OrgGenericAuthSection"; import { OrgGithubSyncSection } from "./OrgGithubSyncSection"; import { OrgLDAPSection } from "./OrgLDAPSection"; import { OrgOIDCSection } from "./OrgOIDCSection"; import { OrgScimSection } from "./OrgSCIMSection"; import { OrgSSOSection } from "./OrgSSOSection"; import { OrgUserAccessTokenLimitSection } from "./OrgUserAccessTokenLimitSection"; 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, isPending: isLoadingOidcConfig } = useGetOIDCConfig( currentOrg?.slug ?? "" ); 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) => !enabledLoginMethods || enabledLoginMethods.includes(method); const isOidcConfigured = oidcConfig && (oidcConfig.discoveryURL || oidcConfig.issuer); const isSamlConfigured = samlConfig && (samlConfig.entryPoint || samlConfig.issuer || samlConfig.cert); 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 } );