Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Revert "fix(auth): show sub-org selector during SAML/OAuth and CLI login"
Sheen7a5ee5c73248
diff --git a/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx b/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsxindex 9b1cc15e4b..aa68ac2a49 100644--- a/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx+++ b/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx@@ -62,34 +62,77 @@ export const PasswordStep = ({providerAuthToken});+ // attemptCliLogin+ const cliUrl = `http://127.0.0.1:${callbackPort}/`;+// unset provider auth token in case it was usedSecurityClient.setProviderAuthToken("");// set JWT tokenSecurityClient.setToken(oauthLogin.token);- if (callbackPort) {- navigateToSelectOrganization(callbackPort, isAdminLogin);- return;- }-+ // case: organization ID is present from the provider auth token -- select the org and use the new jwt token in the CLI, then navigate to the orgif (organizationId) {- const userDuplicateAccount = await fetchUserDuplicateAccounts();- const hasDuplicate = userDuplicateAccount?.length > 1;- if (hasDuplicate) {- setRemoveDuplicateLater(false);- return;- }- }+ const finishWithOrgWorkflow = async () => {+ const { token, isMfaEnabled, mfaMethod } = await selectOrganization({ organizationId });++ if (isMfaEnabled) {+ SecurityClient.setMfaToken(token);+ setMfaSuccessCallback(() => finishWithOrgWorkflow);+ if (mfaMethod) {+ setRequiredMfaMethod(mfaMethod);+ }+ toggleShowMfa.on();+ return;+ }++ if (callbackPort) {+ console.log("organization id was present. new JWT token to be used in CLI:", token);+ const instance = axios.create();+ const payload = {+ privateKey: "", // note(daniel): no longer needed by the CLI, because the CLI only uses the private key to create service tokens, and the private key isn't used anymore when creating service tokens.+ email,+ JTWToken: token+ };+ await instance.post(cliUrl, payload).catch(() => {+ // if error happens to communicate we set the token with an expiry in sessino storage+ // the cli-redirect page has logic to show this to user and ask them to paste it in terminal+ sessionStorage.setItem(+ SessionStorageKeys.CLI_TERMINAL_TOKEN,+ JSON.stringify({+ expiry: formatISO(addSeconds(new Date(), 30)),+ data: window.btoa(JSON.stringify(payload))+ })+ );+ });+ navigate({ to: "/cli-redirect" });+ return;+ }++ const userDuplicateAccount = await fetchUserDuplicateAccounts();+ const hasDuplicate = userDuplicateAccount?.length > 1;+ if (hasDuplicate) {+ setRemoveDuplicateLater(false);+ return;+ }- // case: user has orgs, so we navigate the user to select an org- const userOrgs = await fetchOrganizations();+ await navigateUserToOrg({ navigate, organizationId });+ };- if (userOrgs.length > 0) {- navigateToSelectOrganization(undefined, isAdminLogin);+ await finishWithOrgWorkflow();}- // case: no orgs found, so we navigate the user to create an org+ // case: no organization ID is present -- navigate to the select org page IF the user has any orgs+ // if the user has no orgs, navigate to the create org pageelse {- await navigateUserToOrg({ navigate });+ const userOrgs = await fetchOrganizations();++ // case: user has orgs, so we navigate the user to select an org+ if (userOrgs.length > 0) {+ navigateToSelectOrganization(callbackPort, isAdminLogin);+ }+ // case: no orgs found, so we navigate the user to create an org+ else {+ await navigateUserToOrg({ navigate });+ }}} catch (err: any) {setIsLoading(false);@@ -163,7 +206,7 @@ export const PasswordStep = ({JTWToken: token};await instance.post(cliUrl, payload).catch(() => {- // if error happens to communicate we set the token with an expiry in session storage+ // if error happens to communicate we set the token with an expiry in sessino storage// the cli-redirect page has logic to show this to user and ask them to paste it in terminalsessionStorage.setItem(SessionStorageKeys.CLI_TERMINAL_TOKEN,@@ -184,9 +227,12 @@ export const PasswordStep = ({// if the user has no orgs, navigate to the create org pageconst userOrgs = await fetchOrganizations();+ // case: user has orgs, so we navigate the user to select an orgif (userOrgs.length > 0) {navigateToSelectOrganization(callbackPort, isAdminLogin);- } else {+ }+ // case: no orgs found, so we navigate the user to create an org+ else {await navigateUserToOrg({ navigate });}}diff --git a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsxindex bbcbe1ea68..8bfb8dd885 100644--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx@@ -54,15 +54,6 @@ export const SelectOrganizationSection = () => {const mfaPending = queryParams.get("mfa_pending") === "true";const defaultSelectedOrg = organizations.data?.find((org) => org.id === orgId);- const willAutoSelectDefaultOrg = useMemo(() => {- if (!defaultSelectedOrg || callbackPort || orgsWithSubOrgs.isPending) return false;- const orgEntry = orgsWithSubOrgs.data?.find((o) => o.id === defaultSelectedOrg.id);- return (orgEntry?.subOrganizations.length ?? 0) === 0;- }, [defaultSelectedOrg, callbackPort, orgsWithSubOrgs.isPending, orgsWithSubOrgs.data]);-- const isLoadingSubOrgCheck =- Boolean(defaultSelectedOrg) && !callbackPort && orgsWithSubOrgs.isPending;-const logout = useLogoutUser(true);const handleLogout = useCallback(async () => {try {@@ -138,7 +129,9 @@ export const SelectOrganizationSection = () => {}}} else if (organization.orgAuthMethod === AuthMethod.OIDC) {- url = `/api/v1/sso/oidc/login?orgSlug=${organization.slug}${callbackPort ? `&callbackPort=${callbackPort}` : ""}`;+ url = `/api/v1/sso/oidc/login?orgSlug=${organization.slug}${+ callbackPort ? `&callbackPort=${callbackPort}` : ""+ }`;} else if (organization.orgAuthMethod === AuthMethod.SAML) {url = `/api/v1/sso/redirect/saml2/organizations/${organization.slug}`;if (callbackPort) {@@ -172,6 +165,8 @@ export const SelectOrganizationSection = () => {return;}throw error;+ } finally {+ setIsInitialOrgCheckLoading(false);}await router.invalidate();@@ -181,11 +176,6 @@ export const SelectOrganizationSection = () => {if (mfaMethod) {setRequiredMfaMethod(mfaMethod);}- // Set loading to false only here so the MFA prompt can render.- // For navigation paths below we intentionally leave it true — the- // component unmounts on navigation and setting it false would cause- // a one-frame flash of the org selector before the route change lands.- setIsInitialOrgCheckLoading(false);toggleShowMfa.on();setMfaSuccessCallback(() => () => handleSelectOrganization(organization));return;@@ -292,9 +282,10 @@ export const SelectOrganizationSection = () => {orgsWithSubOrgs.data.length === 1 && orgsWithSubOrgs.data[0].subOrganizations.length === 0;if (onlyOneRootOrgWithNoSubOrgs) {- // CLI flow (callbackPort) or no org_id in URL: auto-select the only org.- // When defaultSelectedOrg is set without callbackPort, willAutoSelectDefaultOrg handles selection via the second useEffect.- if (callbackPort || !defaultSelectedOrg) {+ if (callbackPort) {+ handleCliRedirect();+ setIsInitialOrgCheckLoading(false);+ } else {handleSelectOrganization(organizations.data[0]);}} else {@@ -304,8 +295,7 @@ export const SelectOrganizationSection = () => {organizations.isPending,organizations.data,orgsWithSubOrgs.isPending,- orgsWithSubOrgs.data,- defaultSelectedOrg+ orgsWithSubOrgs.data]);useEffect(() => {@@ -321,10 +311,10 @@ export const SelectOrganizationSection = () => {}}- if (willAutoSelectDefaultOrg && defaultSelectedOrg) {+ if (defaultSelectedOrg) {handleSelectOrganization(defaultSelectedOrg);}- }, [defaultSelectedOrg, mfaPending, willAutoSelectDefaultOrg]);+ }, [defaultSelectedOrg, mfaPending]);const renderListContent = () => {if (orgsWithSubOrgs.isPending) {@@ -502,8 +492,7 @@ export const SelectOrganizationSection = () => {if (userLoading ||!user ||- ((isInitialOrgCheckLoading || willAutoSelectDefaultOrg || isLoadingSubOrgCheck) &&- !shouldShowMfa)+ ((isInitialOrgCheckLoading || defaultSelectedOrg) && !shouldShowMfa)) {return (<div className="h-screen w-screen bg-bunker-800">