use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;
pub struct MultiFactorAuthApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct VerifyChallengeParams {
#[serde(skip)]
pub body: AuthenticationChallengesVerifyRequest,
}
impl VerifyChallengeParams {
#[allow(deprecated)]
pub fn new(body: AuthenticationChallengesVerifyRequest) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct EnrollFactorParams {
#[serde(skip)]
pub body: AuthenticationFactorsCreateRequest,
}
impl EnrollFactorParams {
#[allow(deprecated)]
pub fn new(body: AuthenticationFactorsCreateRequest) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ChallengeFactorParams {
#[serde(skip)]
pub body: ChallengeAuthenticationFactor,
}
impl ChallengeFactorParams {
#[allow(deprecated)]
pub fn new(body: ChallengeAuthenticationFactor) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListUserAuthFactorsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateUserAuthFactorParams {
#[serde(skip)]
pub body: EnrollUserAuthenticationFactor,
}
impl CreateUserAuthFactorParams {
#[allow(deprecated)]
pub fn new(body: EnrollUserAuthenticationFactor) -> Self {
Self { body }
}
}
impl<'a> MultiFactorAuthApi<'a> {
pub async fn verify_challenge(
&self,
id: &str,
params: VerifyChallengeParams,
) -> Result<AuthenticationChallengeVerifyResponse, Error> {
self.verify_challenge_with_options(id, params, None).await
}
pub async fn verify_challenge_with_options(
&self,
id: &str,
params: VerifyChallengeParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuthenticationChallengeVerifyResponse, Error> {
let id = crate::client::path_segment(id);
let path = format!("/auth/challenges/{id}/verify");
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
pub async fn enroll_factor(
&self,
params: EnrollFactorParams,
) -> Result<AuthenticationFactorEnrolled, Error> {
self.enroll_factor_with_options(params, None).await
}
pub async fn enroll_factor_with_options(
&self,
params: EnrollFactorParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuthenticationFactorEnrolled, Error> {
let path = "/auth/factors/enroll".to_string();
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
pub async fn get_factor(&self, id: &str) -> Result<AuthenticationFactor, Error> {
self.get_factor_with_options(id, None).await
}
pub async fn get_factor_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<AuthenticationFactor, Error> {
let id = crate::client::path_segment(id);
let path = format!("/auth/factors/{id}");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
pub async fn delete_factor(&self, id: &str) -> Result<(), Error> {
self.delete_factor_with_options(id, None).await
}
pub async fn delete_factor_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
let id = crate::client::path_segment(id);
let path = format!("/auth/factors/{id}");
let method = http::Method::DELETE;
self.client
.request_with_query_opts_empty(method, &path, &(), options)
.await
}
pub async fn challenge_factor(
&self,
id: &str,
params: ChallengeFactorParams,
) -> Result<AuthenticationChallenge, Error> {
self.challenge_factor_with_options(id, params, None).await
}
pub async fn challenge_factor_with_options(
&self,
id: &str,
params: ChallengeFactorParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuthenticationChallenge, Error> {
let id = crate::client::path_segment(id);
let path = format!("/auth/factors/{id}/challenge");
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
pub async fn list_user_auth_factors(
&self,
userland_user_id: &str,
params: ListUserAuthFactorsParams,
) -> Result<UserAuthenticationFactorList, Error> {
self.list_user_auth_factors_with_options(userland_user_id, params, None)
.await
}
pub async fn list_user_auth_factors_with_options(
&self,
userland_user_id: &str,
params: ListUserAuthFactorsParams,
options: Option<&crate::RequestOptions>,
) -> Result<UserAuthenticationFactorList, Error> {
let userland_user_id = crate::client::path_segment(userland_user_id);
let path = format!("/user_management/users/{userland_user_id}/auth_factors");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
pub fn list_user_auth_factors_auto_paging(
&self,
userland_user_id: impl Into<String>,
params: ListUserAuthFactorsParams,
) -> impl futures_util::Stream<Item = Result<AuthenticationFactor, Error>> + '_ {
let userland_user_id: String = userland_user_id.into();
crate::pagination::auto_paginate_pages(move |after| {
let userland_user_id = userland_user_id.clone();
let mut params = params.clone();
params.after = after;
async move {
let page = self
.list_user_auth_factors(&userland_user_id, params)
.await?;
Ok((page.data, page.list_metadata.after))
}
})
}
pub async fn create_user_auth_factor(
&self,
userland_user_id: &str,
params: CreateUserAuthFactorParams,
) -> Result<UserAuthenticationFactorEnrollResponse, Error> {
self.create_user_auth_factor_with_options(userland_user_id, params, None)
.await
}
pub async fn create_user_auth_factor_with_options(
&self,
userland_user_id: &str,
params: CreateUserAuthFactorParams,
options: Option<&crate::RequestOptions>,
) -> Result<UserAuthenticationFactorEnrollResponse, Error> {
let userland_user_id = crate::client::path_segment(userland_user_id);
let path = format!("/user_management/users/{userland_user_id}/auth_factors");
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
}