1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum OAuthAuthorizeError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum OAuthConsentsError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum OAuthDeleteConsentError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum OAuthGrantCodeError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum OAuthProfileError {
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn o_auth_authorize(configuration: &configuration::Configuration, app_key: &str, scheme: Option<&str>, code: Option<&str>) -> Result<models::AuthorizeResultApiResponse, Error<OAuthAuthorizeError>> {
55 let p_app_key = app_key;
57 let p_scheme = scheme;
58 let p_code = code;
59
60 let uri_str = format!("{}/OAuth/{appKey}/Authorize", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
61 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
62
63 if let Some(ref param_value) = p_scheme {
64 req_builder = req_builder.query(&[("scheme", ¶m_value.to_string())]);
65 }
66 if let Some(ref param_value) = p_code {
67 req_builder = req_builder.query(&[("code", ¶m_value.to_string())]);
68 }
69 if let Some(ref user_agent) = configuration.user_agent {
70 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71 }
72 if let Some(ref token) = configuration.bearer_access_token {
73 req_builder = req_builder.bearer_auth(token.to_owned());
74 };
75
76 let req = req_builder.build()?;
77 let resp = configuration.client.execute(req).await?;
78
79 let status = resp.status();
80 let content_type = resp
81 .headers()
82 .get("content-type")
83 .and_then(|v| v.to_str().ok())
84 .unwrap_or("application/octet-stream");
85 let content_type = super::ContentType::from(content_type);
86
87 if !status.is_client_error() && !status.is_server_error() {
88 let content = resp.text().await?;
89 match content_type {
90 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AuthorizeResultApiResponse`"))),
92 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::AuthorizeResultApiResponse`")))),
93 }
94 } else {
95 let content = resp.text().await?;
96 let entity: Option<OAuthAuthorizeError> = serde_json::from_str(&content).ok();
97 Err(Error::ResponseError(ResponseContent { status, content, entity }))
98 }
99}
100
101pub async fn o_auth_consents(configuration: &configuration::Configuration, app_key: &str) -> Result<models::AppUserConsentModelListApiResponse, Error<OAuthConsentsError>> {
102 let p_app_key = app_key;
104
105 let uri_str = format!("{}/OAuth/{appKey}/Consents", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
106 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
107
108 if let Some(ref user_agent) = configuration.user_agent {
109 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
110 }
111 if let Some(ref token) = configuration.bearer_access_token {
112 req_builder = req_builder.bearer_auth(token.to_owned());
113 };
114
115 let req = req_builder.build()?;
116 let resp = configuration.client.execute(req).await?;
117
118 let status = resp.status();
119 let content_type = resp
120 .headers()
121 .get("content-type")
122 .and_then(|v| v.to_str().ok())
123 .unwrap_or("application/octet-stream");
124 let content_type = super::ContentType::from(content_type);
125
126 if !status.is_client_error() && !status.is_server_error() {
127 let content = resp.text().await?;
128 match content_type {
129 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
130 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AppUserConsentModelListApiResponse`"))),
131 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::AppUserConsentModelListApiResponse`")))),
132 }
133 } else {
134 let content = resp.text().await?;
135 let entity: Option<OAuthConsentsError> = serde_json::from_str(&content).ok();
136 Err(Error::ResponseError(ResponseContent { status, content, entity }))
137 }
138}
139
140pub async fn o_auth_delete_consent(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::BooleanApiResponse, Error<OAuthDeleteConsentError>> {
141 let p_id = id;
143 let p_app_key = app_key;
144
145 let uri_str = format!("{}/OAuth/{appKey}/Consents/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
146 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
147
148 if let Some(ref user_agent) = configuration.user_agent {
149 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
150 }
151 if let Some(ref token) = configuration.bearer_access_token {
152 req_builder = req_builder.bearer_auth(token.to_owned());
153 };
154
155 let req = req_builder.build()?;
156 let resp = configuration.client.execute(req).await?;
157
158 let status = resp.status();
159 let content_type = resp
160 .headers()
161 .get("content-type")
162 .and_then(|v| v.to_str().ok())
163 .unwrap_or("application/octet-stream");
164 let content_type = super::ContentType::from(content_type);
165
166 if !status.is_client_error() && !status.is_server_error() {
167 let content = resp.text().await?;
168 match content_type {
169 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
170 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
171 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::BooleanApiResponse`")))),
172 }
173 } else {
174 let content = resp.text().await?;
175 let entity: Option<OAuthDeleteConsentError> = serde_json::from_str(&content).ok();
176 Err(Error::ResponseError(ResponseContent { status, content, entity }))
177 }
178}
179
180pub async fn o_auth_grant_code(configuration: &configuration::Configuration, app_key: &str, scheme: Option<&str>, grant_request: Option<models::GrantRequest>) -> Result<models::GrantResultApiResponse, Error<OAuthGrantCodeError>> {
181 let p_app_key = app_key;
183 let p_scheme = scheme;
184 let p_grant_request = grant_request;
185
186 let uri_str = format!("{}/OAuth/{appKey}/GrantCode", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
187 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
188
189 if let Some(ref param_value) = p_scheme {
190 req_builder = req_builder.query(&[("scheme", ¶m_value.to_string())]);
191 }
192 if let Some(ref user_agent) = configuration.user_agent {
193 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
194 }
195 if let Some(ref token) = configuration.bearer_access_token {
196 req_builder = req_builder.bearer_auth(token.to_owned());
197 };
198 req_builder = req_builder.json(&p_grant_request);
199
200 let req = req_builder.build()?;
201 let resp = configuration.client.execute(req).await?;
202
203 let status = resp.status();
204 let content_type = resp
205 .headers()
206 .get("content-type")
207 .and_then(|v| v.to_str().ok())
208 .unwrap_or("application/octet-stream");
209 let content_type = super::ContentType::from(content_type);
210
211 if !status.is_client_error() && !status.is_server_error() {
212 let content = resp.text().await?;
213 match content_type {
214 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
215 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GrantResultApiResponse`"))),
216 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::GrantResultApiResponse`")))),
217 }
218 } else {
219 let content = resp.text().await?;
220 let entity: Option<OAuthGrantCodeError> = serde_json::from_str(&content).ok();
221 Err(Error::ResponseError(ResponseContent { status, content, entity }))
222 }
223}
224
225pub async fn o_auth_profile(configuration: &configuration::Configuration, app_key: &str) -> Result<models::ProfileResultApiResponse, Error<OAuthProfileError>> {
226 let p_app_key = app_key;
228
229 let uri_str = format!("{}/OAuth/{appKey}/Profile", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
230 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232 if let Some(ref user_agent) = configuration.user_agent {
233 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
234 }
235 if let Some(ref token) = configuration.bearer_access_token {
236 req_builder = req_builder.bearer_auth(token.to_owned());
237 };
238
239 let req = req_builder.build()?;
240 let resp = configuration.client.execute(req).await?;
241
242 let status = resp.status();
243 let content_type = resp
244 .headers()
245 .get("content-type")
246 .and_then(|v| v.to_str().ok())
247 .unwrap_or("application/octet-stream");
248 let content_type = super::ContentType::from(content_type);
249
250 if !status.is_client_error() && !status.is_server_error() {
251 let content = resp.text().await?;
252 match content_type {
253 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
254 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProfileResultApiResponse`"))),
255 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::ProfileResultApiResponse`")))),
256 }
257 } else {
258 let content = resp.text().await?;
259 let entity: Option<OAuthProfileError> = serde_json::from_str(&content).ok();
260 Err(Error::ResponseError(ResponseContent { status, content, entity }))
261 }
262}
263