propelauth 0.23.5

A Rust crate for managing authentication and authorization with support for multi-tenant / B2B products, powered by PropelAuth
Documentation
/*
 * propelauth
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 0.1.0
 *
 * Generated by: https://openapi-generator.tech
 */

use reqwest;

use super::{configuration, Error};
use crate::propelauth::auth::AUTH_HOSTNAME_HEADER;
use crate::apis::ResponseContent;

/// struct for passing parameters to the method [`verify_step_up_mfa_totp_challenge`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct VerifyTotpChallengeParams {
    pub action_type: String,
    pub user_id: String,
    pub code: String,
    pub grant_type: String,
    pub valid_for_seconds: i64,
}

/// struct for passing parameters to the method [`verify_step_up_grant`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct VerifyStepUpGrantParams {
    pub action_type: String,
    pub user_id: String,
    pub grant: String,
}

/// struct for passing parameters to the method [`send_sms_mfa_code`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct SendSmsMfaCodeParams {
    pub action_type: String,
    pub user_id: String,
    pub mfa_phone_id: String,
    pub grant_type: String,
    pub valid_for_seconds: i64,
}

/// struct for passing parameters to the method [`verify_sms_challenge`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct VerifySmsChallengeParams {
    pub challenge_id: String,
    pub user_id: String,
    pub code: String,
}



#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum StepUpMfaError {
    InvalidIntegrationAPIKey,
    PropelAuthRateLimit,
    NotFound,
    UnknownValue(serde_json::Value),
    UnknownError,
    UnexpectedExceptionWithSDK,
}


pub async fn verify_step_up_totp_challenge(
    configuration: &configuration::Configuration,
    params: VerifyTotpChallengeParams,
) -> Result<crate::models::VerifyTotpChallengeResponse, Error<StepUpMfaError>> {
    let client = &configuration.client;

    let uri = format!(
        "{}/api/backend/v1/mfa/step-up/verify-totp",
        configuration.base_path
    );
    let mut req_builder = client.request(reqwest::Method::POST, uri.as_str());

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref bearer_token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(bearer_token.to_owned());
    }
    req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

    req_builder = req_builder.json(&params);

    let req = req_builder.build()?;
    let resp = client.execute(req).await?;

    let status = resp.status();
    let content = resp.text().await?;

    if !status.is_client_error() && !status.is_server_error() {
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let entity: Option<StepUpMfaError> = serde_json::from_str(&content).ok();
        let error = ResponseContent {
            status,
            content,
            entity,
        };
        Err(Error::ResponseError(error))
    }
}

pub async fn verify_step_up_grant(
    configuration: &configuration::Configuration,
    params: VerifyStepUpGrantParams,
) -> Result<crate::models::SuccessfulResponse, Error<StepUpMfaError>> {
    let client = &configuration.client;

    let uri = format!(
        "{}/api/backend/v1/mfa/step-up/verify-grant",
        configuration.base_path
    );
    let mut req_builder = client.request(reqwest::Method::POST, uri.as_str());

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref bearer_token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(bearer_token.to_owned());
    }
    req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

    req_builder = req_builder.json(&params);

    let req = req_builder.build()?;
    let resp = client.execute(req).await?;

    let status = resp.status();
    let content = resp.text().await?;

    if !status.is_client_error() && !status.is_server_error() {
        Ok(crate::models::successful_response::SuccessfulResponse { message: None })
    } else {
        let entity: Option<StepUpMfaError> = serde_json::from_str(&content).ok();
        let error = ResponseContent {
            status,
            content,
            entity,
        };
        Err(Error::ResponseError(error))
    }
}

pub async fn send_sms_mfa_code(
    configuration: &configuration::Configuration,
    params: SendSmsMfaCodeParams,
) -> Result<crate::models::SendSmsCodeResponse, Error<StepUpMfaError>> {
    let client = &configuration.client;

    let uri = format!(
        "{}/api/backend/v1/mfa/step-up/phone/send",
        configuration.base_path
    );
    let mut req_builder = client.request(reqwest::Method::POST, uri.as_str());

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref bearer_token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(bearer_token.to_owned());
    }
    req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

    req_builder = req_builder.json(&params);

    let req = req_builder.build()?;
    let resp = client.execute(req).await?;

    let status = resp.status();
    let content = resp.text().await?;

    if !status.is_client_error() && !status.is_server_error() {
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let entity: Option<StepUpMfaError> = serde_json::from_str(&content).ok();
        let error = ResponseContent {
            status,
            content,
            entity,
        };
        Err(Error::ResponseError(error))
    }
}

pub async fn verify_sms_challenge(
    configuration: &configuration::Configuration,
    params: VerifySmsChallengeParams,
) -> Result<crate::models::VerifySmsChallengeResponse, Error<StepUpMfaError>> {
    let client = &configuration.client;

    let uri = format!(
        "{}/api/backend/v1/mfa/step-up/phone/verify",
        configuration.base_path
    );
    let mut req_builder = client.request(reqwest::Method::POST, uri.as_str());

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref bearer_token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(bearer_token.to_owned());
    }
    req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

    req_builder = req_builder.json(&params);

    let req = req_builder.build()?;
    let resp = client.execute(req).await?;

    let status = resp.status();
    let content = resp.text().await?;

    if !status.is_client_error() && !status.is_server_error() {
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let entity: Option<StepUpMfaError> = serde_json::from_str(&content).ok();
        let error = ResponseContent {
            status,
            content,
            entity,
        };
        Err(Error::ResponseError(error))
    }
}