Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.5 KB
Raw Blame
use crate::{AuthedClient, Result, error::FusionAuthClientError};

/// Unlinks a user from an identity provider
/// https://fusionauth.io/docs/apis/identity-providers/links#unlink-a-user
/// Valid respones: 200, 400, 401, 404, 500
pub(crate) async fn unlink(
    client: &AuthedClient,
    base_url: &str,
    user_id: &str,
    idp_id: &str,
    idp_user_id: &str,
) -> Result<()> {
    // DELETE /api/identity-provider/link?identityProviderId={identityProviderId}&identityProviderUserId={identityProviderUserId}&userId={userId}
    let res = client.client()
        .delete(format!(
            "{base_url}/api/identity-provider/link?identityProviderId={idp_id}&identityProviderUserId={idp_user_id}&userId={user_id}",
        ))
        .timeout(super::LINK_REQUEST_TIMEOUT)
        .send()
        .await
        .map_err(FusionAuthClientError::transport)?;

    let status = res.status();
    match status {
        reqwest::StatusCode::OK => Ok(()),
        reqwest::StatusCode::NOT_FOUND => Err(FusionAuthClientError::NoIdentityProviderFound), // no idp to unlink
        _ => {
            let headers = res.headers().clone();
            let body = res.text().await.map_err(FusionAuthClientError::transport)?;
            if status == reqwest::StatusCode::BAD_REQUEST && super::link::is_missing_user(&body) {
                return Err(FusionAuthClientError::UserDoesNotExist);
            }
            Err(FusionAuthClientError::unexpected(status, &headers, body))
        }
    }
}