use reqwest;
use crate::apis::ResponseContent;
use super::{Error, configuration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DisconnectUserError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DiscoverOpenIdConfigurationError {
Status401(crate::models::GenericError),
Status500(crate::models::GenericError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum IsInstanceReadyError {
Status503(crate::models::HealthNotReadyStatus),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Oauth2TokenError {
Status401(crate::models::GenericError),
Status500(crate::models::GenericError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OauthAuthError {
Status401(crate::models::GenericError),
Status500(crate::models::GenericError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RevokeOAuth2TokenError {
Status401(crate::models::GenericError),
Status500(crate::models::GenericError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UserinfoError {
Status401(crate::models::GenericError),
Status500(crate::models::GenericError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WellKnownError {
Status500(crate::models::GenericError),
UnknownValue(serde_json::Value),
}
pub async fn disconnect_user(configuration: &configuration::Configuration, ) -> Result<(), Error<DisconnectUserError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/oauth2/sessions/logout", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
Ok(())
} else {
let local_var_entity: Option<DisconnectUserError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn discover_open_id_configuration(configuration: &configuration::Configuration, ) -> Result<crate::models::WellKnown, Error<DiscoverOpenIdConfigurationError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/.well-known/openid-configuration", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<DiscoverOpenIdConfigurationError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn is_instance_ready(configuration: &configuration::Configuration, ) -> Result<crate::models::HealthStatus, Error<IsInstanceReadyError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/health/ready", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<IsInstanceReadyError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn oauth2_token(configuration: &configuration::Configuration, grant_type: &str, code: Option<&str>, refresh_token: Option<&str>, redirect_uri: Option<&str>, client_id: Option<&str>) -> Result<crate::models::Oauth2TokenResponse, Error<Oauth2TokenError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/oauth2/token", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let mut local_var_form_params = std::collections::HashMap::new();
local_var_form_params.insert("grant_type", grant_type.to_string());
if let Some(local_var_param_value) = code {
local_var_form_params.insert("code", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = refresh_token {
local_var_form_params.insert("refresh_token", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = redirect_uri {
local_var_form_params.insert("redirect_uri", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = client_id {
local_var_form_params.insert("client_id", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<Oauth2TokenError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn oauth_auth(configuration: &configuration::Configuration, ) -> Result<(), Error<OauthAuthError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/oauth2/auth", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
Ok(())
} else {
let local_var_entity: Option<OauthAuthError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn revoke_o_auth2_token(configuration: &configuration::Configuration, token: &str) -> Result<(), Error<RevokeOAuth2TokenError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/oauth2/revoke", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let mut local_var_form_params = std::collections::HashMap::new();
local_var_form_params.insert("token", token.to_string());
local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
Ok(())
} else {
let local_var_entity: Option<RevokeOAuth2TokenError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn userinfo(configuration: &configuration::Configuration, ) -> Result<crate::models::UserinfoResponse, Error<UserinfoError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/userinfo", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UserinfoError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn well_known(configuration: &configuration::Configuration, ) -> Result<crate::models::JsonWebKeySet, Error<WellKnownError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/.well-known/jwks.json", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WellKnownError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}