use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AuthJwksGetError {
DefaultResponse(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AuthTokenPostError {
Status400(models::Error),
Status401(models::Error),
Status403(models::Error),
Status500(models::Error),
DefaultResponse(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AuthTokenRefreshPutError {
Status401(models::Error),
Status400(models::Error),
Status500(models::Error),
DefaultResponse(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AuthV2TokenPostError {
Status400(models::Error),
Status401(models::Error),
Status403(models::Error),
Status500(models::Error),
DefaultResponse(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetZkLoginUserDetailsError {
Status400(models::Error),
Status500(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostZkLoginZkpError {
Status400(models::Error),
Status500(models::Error),
UnknownValue(serde_json::Value),
}
pub async fn auth_jwks_get(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<AuthJwksGetError>> {
let uri_str = format!("{}/auth/jwks", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AuthJwksGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn auth_token_post(configuration: &configuration::Configuration, payload_signature: &str, login_request: models::LoginRequest, refresh_token_valid_for_seconds: Option<i64>, read_only: Option<bool>) -> Result<models::LoginResponse, Error<AuthTokenPostError>> {
let p_payload_signature = payload_signature;
let p_login_request = login_request;
let p_refresh_token_valid_for_seconds = refresh_token_valid_for_seconds;
let p_read_only = read_only;
let uri_str = format!("{}/auth/token", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_refresh_token_valid_for_seconds {
req_builder = req_builder.query(&[("refreshTokenValidForSeconds", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_read_only {
req_builder = req_builder.query(&[("readOnly", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("payloadSignature", p_payload_signature.to_string());
req_builder = req_builder.json(&p_login_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LoginResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AuthTokenPostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn auth_token_refresh_put(configuration: &configuration::Configuration, refresh_token_request: models::RefreshTokenRequest) -> Result<models::RefreshTokenResponse, Error<AuthTokenRefreshPutError>> {
let p_refresh_token_request = refresh_token_request;
let uri_str = format!("{}/auth/token/refresh", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_refresh_token_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RefreshTokenResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RefreshTokenResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AuthTokenRefreshPutError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn auth_v2_token_post(configuration: &configuration::Configuration, payload_signature: &str, login_request: models::LoginRequest, refresh_token_valid_for_seconds: Option<i64>, read_only: Option<bool>) -> Result<models::LoginResponse, Error<AuthV2TokenPostError>> {
let p_payload_signature = payload_signature;
let p_login_request = login_request;
let p_refresh_token_valid_for_seconds = refresh_token_valid_for_seconds;
let p_read_only = read_only;
let uri_str = format!("{}/auth/v2/token", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_refresh_token_valid_for_seconds {
req_builder = req_builder.query(&[("refreshTokenValidForSeconds", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_read_only {
req_builder = req_builder.query(&[("readOnly", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("payloadSignature", p_payload_signature.to_string());
req_builder = req_builder.json(&p_login_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LoginResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AuthV2TokenPostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_zk_login_user_details(configuration: &configuration::Configuration, zklogin_jwt: &str) -> Result<models::ZkLoginUserDetailsResponse, Error<GetZkLoginUserDetailsError>> {
let p_zklogin_jwt = zklogin_jwt;
let uri_str = format!("{}/auth/zklogin", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("zklogin-jwt", p_zklogin_jwt.to_string());
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ZkLoginUserDetailsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ZkLoginUserDetailsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetZkLoginUserDetailsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_zk_login_zkp(configuration: &configuration::Configuration, zklogin_jwt: &str, zk_login_zkp_request: models::ZkLoginZkpRequest) -> Result<models::ZkLoginZkpResponse, Error<PostZkLoginZkpError>> {
let p_zklogin_jwt = zklogin_jwt;
let p_zk_login_zkp_request = zk_login_zkp_request;
let uri_str = format!("{}/auth/zklogin/zkp", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("zklogin-jwt", p_zklogin_jwt.to_string());
req_builder = req_builder.json(&p_zk_login_zkp_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ZkLoginZkpResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ZkLoginZkpResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PostZkLoginZkpError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}