1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DisconnectUserError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DiscoverOpenIdConfigurationError {
29 Status401(crate::models::GenericError),
30 Status500(crate::models::GenericError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum IsInstanceReadyError {
38 Status503(crate::models::HealthNotReadyStatus),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum Oauth2TokenError {
46 Status401(crate::models::GenericError),
47 Status500(crate::models::GenericError),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum OauthAuthError {
55 Status401(crate::models::GenericError),
56 Status500(crate::models::GenericError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum RevokeOAuth2TokenError {
64 Status401(crate::models::GenericError),
65 Status500(crate::models::GenericError),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum UserinfoError {
73 Status401(crate::models::GenericError),
74 Status500(crate::models::GenericError),
75 UnknownValue(serde_json::Value),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum WellKnownError {
82 Status500(crate::models::GenericError),
83 UnknownValue(serde_json::Value),
84}
85
86
87pub async fn disconnect_user(configuration: &configuration::Configuration, ) -> Result<(), Error<DisconnectUserError>> {
89
90 let local_var_client = &configuration.client;
91
92 let local_var_uri_str = format!("{}/oauth2/sessions/logout", configuration.base_path);
93 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
94
95 if let Some(ref local_var_user_agent) = configuration.user_agent {
96 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97 }
98
99 let local_var_req = local_var_req_builder.build()?;
100 let local_var_resp = local_var_client.execute(local_var_req).await?;
101
102 let local_var_status = local_var_resp.status();
103 let local_var_content = local_var_resp.text().await?;
104
105 if local_var_status.is_success() {
106 Ok(())
107 } else {
108 let local_var_entity: Option<DisconnectUserError> = serde_json::from_str(&local_var_content).ok();
109 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
110 Err(Error::ResponseError(local_var_error))
111 }
112}
113
114pub async fn discover_open_id_configuration(configuration: &configuration::Configuration, ) -> Result<crate::models::WellKnown, Error<DiscoverOpenIdConfigurationError>> {
116
117 let local_var_client = &configuration.client;
118
119 let local_var_uri_str = format!("{}/.well-known/openid-configuration", configuration.base_path);
120 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
121
122 if let Some(ref local_var_user_agent) = configuration.user_agent {
123 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
124 }
125
126 let local_var_req = local_var_req_builder.build()?;
127 let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129 let local_var_status = local_var_resp.status();
130 let local_var_content = local_var_resp.text().await?;
131
132 if local_var_status.is_success() {
133 serde_json::from_str(&local_var_content).map_err(Error::from)
134 } else {
135 let local_var_entity: Option<DiscoverOpenIdConfigurationError> = serde_json::from_str(&local_var_content).ok();
136 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
137 Err(Error::ResponseError(local_var_error))
138 }
139}
140
141pub async fn is_instance_ready(configuration: &configuration::Configuration, ) -> Result<crate::models::HealthStatus, Error<IsInstanceReadyError>> {
143
144 let local_var_client = &configuration.client;
145
146 let local_var_uri_str = format!("{}/health/ready", configuration.base_path);
147 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
148
149 if let Some(ref local_var_user_agent) = configuration.user_agent {
150 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
151 }
152
153 let local_var_req = local_var_req_builder.build()?;
154 let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156 let local_var_status = local_var_resp.status();
157 let local_var_content = local_var_resp.text().await?;
158
159 if local_var_status.is_success() {
160 serde_json::from_str(&local_var_content).map_err(Error::from)
161 } else {
162 let local_var_entity: Option<IsInstanceReadyError> = serde_json::from_str(&local_var_content).ok();
163 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
164 Err(Error::ResponseError(local_var_error))
165 }
166}
167
168pub 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>> {
170
171 let local_var_client = &configuration.client;
172
173 let local_var_uri_str = format!("{}/oauth2/token", configuration.base_path);
174 let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
175
176 if let Some(ref local_var_user_agent) = configuration.user_agent {
177 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
178 }
179 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
180 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
181 };
182 if let Some(ref local_var_token) = configuration.oauth_access_token {
183 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184 };
185 let mut local_var_form_params = std::collections::HashMap::new();
186 local_var_form_params.insert("grant_type", grant_type.to_string());
187 if let Some(local_var_param_value) = code {
188 local_var_form_params.insert("code", local_var_param_value.to_string());
189 }
190 if let Some(local_var_param_value) = refresh_token {
191 local_var_form_params.insert("refresh_token", local_var_param_value.to_string());
192 }
193 if let Some(local_var_param_value) = redirect_uri {
194 local_var_form_params.insert("redirect_uri", local_var_param_value.to_string());
195 }
196 if let Some(local_var_param_value) = client_id {
197 local_var_form_params.insert("client_id", local_var_param_value.to_string());
198 }
199 local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
200
201 let local_var_req = local_var_req_builder.build()?;
202 let local_var_resp = local_var_client.execute(local_var_req).await?;
203
204 let local_var_status = local_var_resp.status();
205 let local_var_content = local_var_resp.text().await?;
206
207 if local_var_status.is_success() {
208 serde_json::from_str(&local_var_content).map_err(Error::from)
209 } else {
210 let local_var_entity: Option<Oauth2TokenError> = serde_json::from_str(&local_var_content).ok();
211 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
212 Err(Error::ResponseError(local_var_error))
213 }
214}
215
216pub async fn oauth_auth(configuration: &configuration::Configuration, ) -> Result<(), Error<OauthAuthError>> {
218
219 let local_var_client = &configuration.client;
220
221 let local_var_uri_str = format!("{}/oauth2/auth", configuration.base_path);
222 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
223
224 if let Some(ref local_var_user_agent) = configuration.user_agent {
225 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226 }
227
228 let local_var_req = local_var_req_builder.build()?;
229 let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231 let local_var_status = local_var_resp.status();
232 let local_var_content = local_var_resp.text().await?;
233
234 if local_var_status.is_success() {
235 Ok(())
236 } else {
237 let local_var_entity: Option<OauthAuthError> = serde_json::from_str(&local_var_content).ok();
238 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239 Err(Error::ResponseError(local_var_error))
240 }
241}
242
243pub async fn revoke_o_auth2_token(configuration: &configuration::Configuration, token: &str) -> Result<(), Error<RevokeOAuth2TokenError>> {
245
246 let local_var_client = &configuration.client;
247
248 let local_var_uri_str = format!("{}/oauth2/revoke", configuration.base_path);
249 let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
250
251 if let Some(ref local_var_user_agent) = configuration.user_agent {
252 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
253 }
254 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
255 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
256 };
257 if let Some(ref local_var_token) = configuration.oauth_access_token {
258 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
259 };
260 let mut local_var_form_params = std::collections::HashMap::new();
261 local_var_form_params.insert("token", token.to_string());
262 local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
263
264 let local_var_req = local_var_req_builder.build()?;
265 let local_var_resp = local_var_client.execute(local_var_req).await?;
266
267 let local_var_status = local_var_resp.status();
268 let local_var_content = local_var_resp.text().await?;
269
270 if local_var_status.is_success() {
271 Ok(())
272 } else {
273 let local_var_entity: Option<RevokeOAuth2TokenError> = serde_json::from_str(&local_var_content).ok();
274 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
275 Err(Error::ResponseError(local_var_error))
276 }
277}
278
279pub async fn userinfo(configuration: &configuration::Configuration, ) -> Result<crate::models::UserinfoResponse, Error<UserinfoError>> {
281
282 let local_var_client = &configuration.client;
283
284 let local_var_uri_str = format!("{}/userinfo", configuration.base_path);
285 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
286
287 if let Some(ref local_var_user_agent) = configuration.user_agent {
288 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289 }
290 if let Some(ref local_var_token) = configuration.oauth_access_token {
291 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
292 };
293
294 let local_var_req = local_var_req_builder.build()?;
295 let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297 let local_var_status = local_var_resp.status();
298 let local_var_content = local_var_resp.text().await?;
299
300 if local_var_status.is_success() {
301 serde_json::from_str(&local_var_content).map_err(Error::from)
302 } else {
303 let local_var_entity: Option<UserinfoError> = serde_json::from_str(&local_var_content).ok();
304 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
305 Err(Error::ResponseError(local_var_error))
306 }
307}
308
309pub async fn well_known(configuration: &configuration::Configuration, ) -> Result<crate::models::JsonWebKeySet, Error<WellKnownError>> {
311
312 let local_var_client = &configuration.client;
313
314 let local_var_uri_str = format!("{}/.well-known/jwks.json", configuration.base_path);
315 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
316
317 if let Some(ref local_var_user_agent) = configuration.user_agent {
318 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
319 }
320
321 let local_var_req = local_var_req_builder.build()?;
322 let local_var_resp = local_var_client.execute(local_var_req).await?;
323
324 let local_var_status = local_var_resp.status();
325 let local_var_content = local_var_resp.text().await?;
326
327 if local_var_status.is_success() {
328 serde_json::from_str(&local_var_content).map_err(Error::from)
329 } else {
330 let local_var_entity: Option<WellKnownError> = serde_json::from_str(&local_var_content).ok();
331 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
332 Err(Error::ResponseError(local_var_error))
333 }
334}
335