Skip to main content

auths_cli/commands/id/
bind_idp.rs

1use anyhow::{Result, anyhow};
2use clap::Parser;
3
4const CLOUD_BINARY: &str = "auths-cloud";
5
6/// Stub command that delegates to the `auths-cloud` binary.
7///
8/// If `auths-cloud` is on `$PATH`, forwards all arguments.
9/// Otherwise, prints an informational message about Auths Cloud.
10#[derive(Parser, Debug, Clone)]
11#[command(about = "Bind this identity to an enterprise IdP (requires Auths Cloud)")]
12pub struct BindIdpStubCommand {
13    /// All arguments are forwarded to auths-cloud.
14    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
15    args: Vec<String>,
16}
17
18pub fn handle_bind_idp(cmd: BindIdpStubCommand) -> Result<()> {
19    match which::which(CLOUD_BINARY) {
20        Ok(path) => {
21            let status = std::process::Command::new(path)
22                .args(["id", "bind-idp"])
23                .args(&cmd.args)
24                .status()
25                .map_err(|e| anyhow!("failed to execute {CLOUD_BINARY}: {e}"))?;
26
27            if status.success() {
28                Ok(())
29            } else {
30                Err(anyhow!(
31                    "{CLOUD_BINARY} exited with status {}",
32                    status.code().unwrap_or(-1)
33                ))
34            }
35        }
36        Err(_) => {
37            let out = crate::ux::format::Output::new();
38            out.newline();
39            out.print_info("IdP binding requires Auths Cloud.");
40            out.newline();
41            out.println("  Bind your Auths identity to enterprise identity providers");
42            out.println("  like Okta, Microsoft Entra ID, Google Workspace, or SAML 2.0.");
43            out.newline();
44            out.println("  Learn more: https://auths.dev/cloud");
45            out.newline();
46            Ok(())
47        }
48    }
49}