From 898ee667087b95f127c61cfb8c1702fd50464291 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 15:54:57 +0000 Subject: [PATCH 1/4] feat(orgs): floo orgs sso directory, and directory sync in sso status `floo orgs sso directory` opens a short-lived WorkOS portal to connect or manage an Enterprise org's SCIM directory. `floo orgs sso status` shows the directory's provider, state, people count, last sync, and any issue that needs an admin. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Eufw44dm18PKbSX4ed96z6 --- src/api_client.rs | 9 ++++- src/api_types.rs | 12 +++++++ src/cli.rs | 16 ++++++++- src/commands/organization_sso.rs | 60 +++++++++++++++++++++++++++----- tests/mock_api_tests.rs | 58 ++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 10 deletions(-) diff --git a/src/api_client.rs b/src/api_client.rs index dc597c5..a3c8860 100644 --- a/src/api_client.rs +++ b/src/api_client.rs @@ -332,12 +332,19 @@ impl FlooClient { self.handle_response(resp) } + /// Opens the provider's setup portal for SSO, or with `directory` for the SCIM directory. pub fn create_organization_sso_portal( &self, org_id: &str, + directory: bool, ) -> Result { + let path = if directory { + "sso/directory/portal-session" + } else { + "sso/portal-session" + }; let resp = self.post_json( - &format!("/v1/organizations/{org_id}/sso/portal-session"), + &format!("/v1/organizations/{org_id}/{path}"), &serde_json::json!({}), )?; self.handle_response(resp) diff --git a/src/api_types.rs b/src/api_types.rs index 1dbf1ab..9032b32 100644 --- a/src/api_types.rs +++ b/src/api_types.rs @@ -443,6 +443,18 @@ pub struct OrganizationSsoStatusResponse { pub enforcement_policy: OrganizationSsoEnforcementPolicy, pub recovery_ready: bool, pub observed_at: Option, + pub directory: Option, +} + +/// The org's SCIM directory as floo last synced it. `status`, `provider_type`, and `issue` +/// stay strings: they are the provider's and the API's words, shown rather than branched on. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct OrganizationDirectoryStatus { + pub status: String, + pub provider_type: String, + pub synced_at: Option, + pub issue: Option, + pub people: u64, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/cli.rs b/src/cli.rs index 0cfd2af..74db439 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -907,6 +907,17 @@ pub enum OrganizationSsoCommands { no_browser: bool, }, + /// Open a short-lived portal to connect or manage the SCIM directory. + Directory { + /// Organization slug or ID. Uses the current organization when omitted. + #[arg(long)] + org: Option, + + /// Print the portal URL without opening a browser. + #[arg(long)] + no_browser: bool, + }, + /// Verify with SSO in the dashboard and enable enforcement. Enforce { /// Organization slug or ID. Uses the current organization when omitted. @@ -2402,7 +2413,10 @@ pub fn run() { commands::organization_sso::status(org.as_deref()) } OrganizationSsoCommands::Portal { org, no_browser } => { - commands::organization_sso::portal(org.as_deref(), no_browser) + commands::organization_sso::portal(org.as_deref(), no_browser, false) + } + OrganizationSsoCommands::Directory { org, no_browser } => { + commands::organization_sso::portal(org.as_deref(), no_browser, true) } OrganizationSsoCommands::Enforce { org, no_browser } => { commands::organization_sso::enforce(org.as_deref(), no_browser) diff --git a/src/commands/organization_sso.rs b/src/commands/organization_sso.rs index 8031837..03a4637 100644 --- a/src/commands/organization_sso.rs +++ b/src/commands/organization_sso.rs @@ -2,11 +2,11 @@ use std::process; use crate::api_client::FlooClient; use crate::api_types::{ - OrgResponse, OrganizationSsoBrowserHandoff, OrganizationSsoCredentialStatus, - OrganizationSsoDoctorResponse, OrganizationSsoEnforcementAccess, - OrganizationSsoEnforcementPolicy, OrganizationSsoLifecycle, OrganizationSsoNextAction, - OrganizationSsoProviderReachability, OrganizationSsoProviderState, OrganizationSsoProviderType, - OrganizationSsoStatusResponse, + OrgResponse, OrganizationDirectoryStatus, OrganizationSsoBrowserHandoff, + OrganizationSsoCredentialStatus, OrganizationSsoDoctorResponse, + OrganizationSsoEnforcementAccess, OrganizationSsoEnforcementPolicy, OrganizationSsoLifecycle, + OrganizationSsoNextAction, OrganizationSsoProviderReachability, OrganizationSsoProviderState, + OrganizationSsoProviderType, OrganizationSsoStatusResponse, }; use crate::config::{load_config, FlooConfig}; use crate::errors::{ErrorCode, FlooApiError}; @@ -47,18 +47,22 @@ pub fn doctor(org_selector: Option<&str>) { } } -pub fn portal(org_selector: Option<&str>, no_browser: bool) { +pub fn portal(org_selector: Option<&str>, no_browser: bool, directory: bool) { let context = resolve_organization(org_selector); match context .client - .create_organization_sso_portal(&context.org.id) + .create_organization_sso_portal(&context.org.id, directory) { Ok(portal) => { if output::is_json_mode() { output::success("", Some(output::to_value(&portal))); return; } - output::success("Created a short-lived SSO setup session.", None); + let subject = if directory { "directory" } else { "SSO" }; + output::success( + &format!("Created a short-lived {subject} setup session."), + None, + ); output::info(&format!(" {}", portal.url), None); if !no_browser { open_browser(&portal.url); @@ -219,6 +223,17 @@ fn render_status(org: &OrgResponse, status: &OrganizationSsoStatusResponse) { .join(", "); output::info(&format!("Domains: {domains}"), None); } + output::info( + &format!( + "Directory: {}", + status + .directory + .as_ref() + .map(directory_label) + .unwrap_or_else(|| "Not connected".to_string()) + ), + None, + ); let selector = org.display_name().unwrap_or(org.id.as_str()); if status.lifecycle != OrganizationSsoLifecycle::Enabled || status.status != OrganizationSsoProviderState::Active @@ -235,6 +250,35 @@ fn render_status(org: &OrgResponse, status: &OrganizationSsoStatusResponse) { } } +fn directory_label(directory: &OrganizationDirectoryStatus) -> String { + let synced = directory.synced_at.as_deref().unwrap_or("never"); + let mut label = format!( + "{} ({}), {} people, synced {synced}", + string_label(&directory.provider_type), + string_label(&directory.status), + directory.people, + ); + if let Some(issue) = directory.issue.as_deref() { + label.push_str(&format!( + ", needs attention: {}", + directory_issue_label(issue) + )); + } + label +} + +fn directory_issue_label(issue: &str) -> &str { + match issue { + "multiple_directories" => "more than one directory is connected; remove the extra one", + "provider_unavailable" => "the directory could not be read; floo retries every 5 minutes", + "last_admin_kept" => { + "the directory removed the only admin; make someone else an admin to finish" + } + "invite_email_failed" => "an invite email failed; floo retries every hour", + other => string_label(other), + } +} + fn render_doctor(org: &OrgResponse, doctor: &OrganizationSsoDoctorResponse) { if output::is_json_mode() { output::success("", Some(output::to_value(doctor))); diff --git a/tests/mock_api_tests.rs b/tests/mock_api_tests.rs index 075e791..582daab 100644 --- a/tests/mock_api_tests.rs +++ b/tests/mock_api_tests.rs @@ -811,6 +811,64 @@ fn test_orgs_sso_portal_json_returns_short_lived_url_once() { .stdout(predicate::str::contains(r#""expires_in_seconds":300"#)); } +#[test] +fn test_orgs_sso_directory_json_returns_the_directory_portal_url() { + let mut server = Server::new(); + let home = setup_config(&server); + let _org = mock_org_me(&mut server); + let _portal = server + .mock( + "POST", + format!("/v1/organizations/{TEST_ORG_ID}/sso/directory/portal-session").as_str(), + ) + .match_header("x-floo-org-id", TEST_ORG_ID) + .with_status(200) + .with_header("content-type", "application/json") + .with_body( + r#"{"id":"sso-config-1","url":"https://setup.example.test/launch/dsync","expires_in_seconds":300}"#, + ) + .create(); + + floo() + .args(["--json", "orgs", "sso", "directory"]) + .env("HOME", home.path()) + .assert() + .success() + .stdout(predicate::str::contains( + "https://setup.example.test/launch/dsync", + )); +} + +#[test] +fn test_orgs_sso_status_shows_the_directory_and_its_issue() { + let mut server = Server::new(); + let home = setup_config(&server); + let _org = mock_org_me(&mut server); + let body = sso_status_json().replace( + r#""observed_at":"2026-08-28T12:00:00Z"}"#, + r#""observed_at":"2026-08-28T12:00:00Z","directory":{"status":"linked","provider_type":"okta scim v2.0","synced_at":"2026-11-18T12:00:00Z","issue":"last_admin_kept","people":42}}"#, + ); + let _status = server + .mock( + "GET", + format!("/v1/organizations/{TEST_ORG_ID}/sso").as_str(), + ) + .with_status(200) + .with_header("content-type", "application/json") + .with_body(body) + .create(); + + floo() + .args(["orgs", "sso", "status"]) + .env("HOME", home.path()) + .assert() + .success() + .stderr(predicate::str::contains( + "okta scim v2.0 (linked), 42 people, synced 2026-11-18T12:00:00Z", + )) + .stderr(predicate::str::contains("make someone else an admin")); +} + #[test] fn test_orgs_sso_enforce_json_returns_browser_handoff_without_opening() { let mut server = Server::new(); From 90329470edca09ce4b57656629525a3874d03515 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 16:05:47 +0000 Subject: [PATCH 2/4] feat(orgs): name the not_linked directory issue Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Eufw44dm18PKbSX4ed96z6 --- src/commands/organization_sso.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/organization_sso.rs b/src/commands/organization_sso.rs index 03a4637..1d54628 100644 --- a/src/commands/organization_sso.rs +++ b/src/commands/organization_sso.rs @@ -271,6 +271,7 @@ fn directory_issue_label(issue: &str) -> &str { match issue { "multiple_directories" => "more than one directory is connected; remove the extra one", "provider_unavailable" => "the directory could not be read; floo retries every 5 minutes", + "not_linked" => "the directory is not linked yet, so nobody is added or removed", "last_admin_kept" => { "the directory removed the only admin; make someone else an admin to finish" } From 30d3be37bb8de3a4c276d84a970681e4b38bb8b3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 16:15:13 +0000 Subject: [PATCH 3/4] fix(orgs): redact SSO and directory portal links in --json output The setup portal link opens a live WorkOS Admin Portal session for whoever holds it. It is now emitted as portal_url, which the redactor treats as a secret unless --reveal-secrets is set, for both sso portal and sso directory. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Eufw44dm18PKbSX4ed96z6 --- src/api_types.rs | 3 +++ src/redact.rs | 24 ++++++++++++++++++++++++ tests/mock_api_tests.rs | 15 ++++++++------- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/api_types.rs b/src/api_types.rs index 9032b32..d85daff 100644 --- a/src/api_types.rs +++ b/src/api_types.rs @@ -470,6 +470,9 @@ pub struct OrganizationSsoDoctorResponse { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OrganizationSsoPortalSessionResponse { pub id: String, + /// A live Admin Portal session for whoever holds it: emitted as `portal_url`, which the + /// `--json` redactor treats as a secret unless `--reveal-secrets` is set. + #[serde(rename(serialize = "portal_url"))] pub url: String, pub expires_in_seconds: u64, } diff --git a/src/redact.rs b/src/redact.rs index 7784b61..bee5a06 100644 --- a/src/redact.rs +++ b/src/redact.rs @@ -79,6 +79,7 @@ const SECRET_FIELD_NAMES: &[&str] = &[ "connection_url", "webhook_url", "invite_url", + "portal_url", "generated_password", "encrypted_value", ]; @@ -978,6 +979,29 @@ mod snapshots { ); } + /// `floo orgs sso portal|directory --json`: the setup portal link opens a WorkOS + /// Admin Portal session for anyone who holds it, so it is a credential. + #[test] + fn sso_portal_session_url_redacted() { + let _g = lock_default_redact(); + let payload = json!({ + "success": true, + "data": { + "id": "sso-config-1", + "portal_url": "https://setup.example.test/launch/supersecretvaluethatshouldnotleak", + "expires_in_seconds": 300, + } + }); + let out = through_print_json(payload); + let leaks = collect_leaks(&out); + assert!( + leaks.is_empty(), + "portal link survived redaction: {leaks:?}" + ); + assert_eq!(out["contains_secrets"], true); + assert_eq!(out["data"]["expires_in_seconds"], 300); + } + /// Sweep test: kitchen-sink payload combining every leak vector. /// If any future change skips a branch in the redactor, this /// fails before it reaches users. diff --git a/tests/mock_api_tests.rs b/tests/mock_api_tests.rs index 582daab..3c2b796 100644 --- a/tests/mock_api_tests.rs +++ b/tests/mock_api_tests.rs @@ -805,14 +805,14 @@ fn test_orgs_sso_portal_json_returns_short_lived_url_once() { .env("HOME", home.path()) .assert() .success() - .stdout(predicate::str::contains( - "https://setup.example.test/launch/ephemeral", - )) + // The portal link opens a live setup session: redacted unless revealed. + .stdout(predicate::str::contains("launch/ephemeral").not()) + .stdout(predicate::str::contains("contains_secrets")) .stdout(predicate::str::contains(r#""expires_in_seconds":300"#)); } #[test] -fn test_orgs_sso_directory_json_returns_the_directory_portal_url() { +fn test_orgs_sso_directory_json_reveals_the_portal_url_only_when_asked() { let mut server = Server::new(); let home = setup_config(&server); let _org = mock_org_me(&mut server); @@ -830,13 +830,14 @@ fn test_orgs_sso_directory_json_returns_the_directory_portal_url() { .create(); floo() - .args(["--json", "orgs", "sso", "directory"]) + .args(["--json", "--reveal-secrets", "orgs", "sso", "directory"]) .env("HOME", home.path()) .assert() .success() .stdout(predicate::str::contains( - "https://setup.example.test/launch/dsync", - )); + r#""portal_url":"https://setup.example.test/launch/dsync""#, + )) + .stdout(predicate::str::contains("contains_secrets")); } #[test] From 11d5269e199b948aa14ad0f9952da823ebd65da2 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 16:18:38 +0000 Subject: [PATCH 4/4] feat(orgs): show when directory sync is paused Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Eufw44dm18PKbSX4ed96z6 --- src/api_types.rs | 2 ++ src/commands/organization_sso.rs | 3 +++ tests/mock_api_tests.rs | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api_types.rs b/src/api_types.rs index d85daff..1404f24 100644 --- a/src/api_types.rs +++ b/src/api_types.rs @@ -455,6 +455,8 @@ pub struct OrganizationDirectoryStatus { pub synced_at: Option, pub issue: Option, pub people: u64, + /// False while floo is not syncing it: the org is not on Enterprise or SSO is not enabled. + pub syncing: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/commands/organization_sso.rs b/src/commands/organization_sso.rs index 1d54628..6da4489 100644 --- a/src/commands/organization_sso.rs +++ b/src/commands/organization_sso.rs @@ -258,6 +258,9 @@ fn directory_label(directory: &OrganizationDirectoryStatus) -> String { string_label(&directory.status), directory.people, ); + if !directory.syncing { + label.push_str(", sync paused until SSO is enabled on an Enterprise plan"); + } if let Some(issue) = directory.issue.as_deref() { label.push_str(&format!( ", needs attention: {}", diff --git a/tests/mock_api_tests.rs b/tests/mock_api_tests.rs index 3c2b796..f200b9c 100644 --- a/tests/mock_api_tests.rs +++ b/tests/mock_api_tests.rs @@ -847,7 +847,7 @@ fn test_orgs_sso_status_shows_the_directory_and_its_issue() { let _org = mock_org_me(&mut server); let body = sso_status_json().replace( r#""observed_at":"2026-08-28T12:00:00Z"}"#, - r#""observed_at":"2026-08-28T12:00:00Z","directory":{"status":"linked","provider_type":"okta scim v2.0","synced_at":"2026-11-18T12:00:00Z","issue":"last_admin_kept","people":42}}"#, + r#""observed_at":"2026-08-28T12:00:00Z","directory":{"status":"linked","provider_type":"okta scim v2.0","synced_at":"2026-11-18T12:00:00Z","issue":"last_admin_kept","people":42,"syncing":true}}"#, ); let _status = server .mock(