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 CreateOidcDynamicClientError {
22 Status400(models::ErrorOAuth2),
23 DefaultResponse(models::ErrorOAuth2),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CreateVerifiableCredentialError {
31 Status400(models::VerifiableCredentialPrimingResponse),
32 DefaultResponse(models::ErrorOAuth2),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteOidcDynamicClientError {
40 DefaultResponse(models::GenericError),
41 UnknownValue(serde_json::Value),
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum DiscoverOidcConfigurationError {
48 DefaultResponse(models::ErrorOAuth2),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum GetOidcDynamicClientError {
56 DefaultResponse(models::ErrorOAuth2),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetOidcUserInfoError {
64 DefaultResponse(models::ErrorOAuth2),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum RevokeOidcSessionError {
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum SetOidcDynamicClientError {
79 Status404(models::ErrorOAuth2),
80 DefaultResponse(models::ErrorOAuth2),
81 UnknownValue(serde_json::Value),
82}
83
84
85pub async fn create_oidc_dynamic_client(configuration: &configuration::Configuration, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<CreateOidcDynamicClientError>> {
87 let p_o_auth2_client = o_auth2_client;
89
90 let uri_str = format!("{}/oauth2/register", configuration.base_path);
91 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
92
93 if let Some(ref user_agent) = configuration.user_agent {
94 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95 }
96 req_builder = req_builder.json(&p_o_auth2_client);
97
98 let req = req_builder.build()?;
99 let resp = configuration.client.execute(req).await?;
100
101 let status = resp.status();
102 let content_type = resp
103 .headers()
104 .get("content-type")
105 .and_then(|v| v.to_str().ok())
106 .unwrap_or("application/octet-stream");
107 let content_type = super::ContentType::from(content_type);
108
109 if !status.is_client_error() && !status.is_server_error() {
110 let content = resp.text().await?;
111 match content_type {
112 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
114 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::OAuth2Client`")))),
115 }
116 } else {
117 let content = resp.text().await?;
118 let entity: Option<CreateOidcDynamicClientError> = serde_json::from_str(&content).ok();
119 Err(Error::ResponseError(ResponseContent { status, content, entity }))
120 }
121}
122
123pub async fn create_verifiable_credential(configuration: &configuration::Configuration, create_verifiable_credential_request_body: Option<models::CreateVerifiableCredentialRequestBody>) -> Result<models::VerifiableCredentialResponse, Error<CreateVerifiableCredentialError>> {
125 let p_create_verifiable_credential_request_body = create_verifiable_credential_request_body;
127
128 let uri_str = format!("{}/credentials", configuration.base_path);
129 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
130
131 if let Some(ref user_agent) = configuration.user_agent {
132 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133 }
134 req_builder = req_builder.json(&p_create_verifiable_credential_request_body);
135
136 let req = req_builder.build()?;
137 let resp = configuration.client.execute(req).await?;
138
139 let status = resp.status();
140 let content_type = resp
141 .headers()
142 .get("content-type")
143 .and_then(|v| v.to_str().ok())
144 .unwrap_or("application/octet-stream");
145 let content_type = super::ContentType::from(content_type);
146
147 if !status.is_client_error() && !status.is_server_error() {
148 let content = resp.text().await?;
149 match content_type {
150 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerifiableCredentialResponse`"))),
152 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::VerifiableCredentialResponse`")))),
153 }
154 } else {
155 let content = resp.text().await?;
156 let entity: Option<CreateVerifiableCredentialError> = serde_json::from_str(&content).ok();
157 Err(Error::ResponseError(ResponseContent { status, content, entity }))
158 }
159}
160
161pub async fn delete_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteOidcDynamicClientError>> {
163 let p_id = id;
165
166 let uri_str = format!("{}/oauth2/register/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
167 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
168
169 if let Some(ref user_agent) = configuration.user_agent {
170 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171 }
172 if let Some(ref token) = configuration.bearer_access_token {
173 req_builder = req_builder.bearer_auth(token.to_owned());
174 };
175
176 let req = req_builder.build()?;
177 let resp = configuration.client.execute(req).await?;
178
179 let status = resp.status();
180
181 if !status.is_client_error() && !status.is_server_error() {
182 Ok(())
183 } else {
184 let content = resp.text().await?;
185 let entity: Option<DeleteOidcDynamicClientError> = serde_json::from_str(&content).ok();
186 Err(Error::ResponseError(ResponseContent { status, content, entity }))
187 }
188}
189
190pub async fn discover_oidc_configuration(configuration: &configuration::Configuration, ) -> Result<models::OidcConfiguration, Error<DiscoverOidcConfigurationError>> {
192
193 let uri_str = format!("{}/.well-known/openid-configuration", configuration.base_path);
194 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
195
196 if let Some(ref user_agent) = configuration.user_agent {
197 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
198 }
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::OidcConfiguration`"))),
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::OidcConfiguration`")))),
217 }
218 } else {
219 let content = resp.text().await?;
220 let entity: Option<DiscoverOidcConfigurationError> = serde_json::from_str(&content).ok();
221 Err(Error::ResponseError(ResponseContent { status, content, entity }))
222 }
223}
224
225pub async fn get_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str) -> Result<models::OAuth2Client, Error<GetOidcDynamicClientError>> {
227 let p_id = id;
229
230 let uri_str = format!("{}/oauth2/register/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
231 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
232
233 if let Some(ref user_agent) = configuration.user_agent {
234 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
235 }
236 if let Some(ref token) = configuration.bearer_access_token {
237 req_builder = req_builder.bearer_auth(token.to_owned());
238 };
239
240 let req = req_builder.build()?;
241 let resp = configuration.client.execute(req).await?;
242
243 let status = resp.status();
244 let content_type = resp
245 .headers()
246 .get("content-type")
247 .and_then(|v| v.to_str().ok())
248 .unwrap_or("application/octet-stream");
249 let content_type = super::ContentType::from(content_type);
250
251 if !status.is_client_error() && !status.is_server_error() {
252 let content = resp.text().await?;
253 match content_type {
254 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
256 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::OAuth2Client`")))),
257 }
258 } else {
259 let content = resp.text().await?;
260 let entity: Option<GetOidcDynamicClientError> = serde_json::from_str(&content).ok();
261 Err(Error::ResponseError(ResponseContent { status, content, entity }))
262 }
263}
264
265pub async fn get_oidc_user_info(configuration: &configuration::Configuration, ) -> Result<models::OidcUserInfo, Error<GetOidcUserInfoError>> {
267
268 let uri_str = format!("{}/userinfo", configuration.base_path);
269 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
270
271 if let Some(ref user_agent) = configuration.user_agent {
272 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
273 }
274 if let Some(ref token) = configuration.oauth_access_token {
275 req_builder = req_builder.bearer_auth(token.to_owned());
276 };
277
278 let req = req_builder.build()?;
279 let resp = configuration.client.execute(req).await?;
280
281 let status = resp.status();
282 let content_type = resp
283 .headers()
284 .get("content-type")
285 .and_then(|v| v.to_str().ok())
286 .unwrap_or("application/octet-stream");
287 let content_type = super::ContentType::from(content_type);
288
289 if !status.is_client_error() && !status.is_server_error() {
290 let content = resp.text().await?;
291 match content_type {
292 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
293 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OidcUserInfo`"))),
294 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::OidcUserInfo`")))),
295 }
296 } else {
297 let content = resp.text().await?;
298 let entity: Option<GetOidcUserInfoError> = serde_json::from_str(&content).ok();
299 Err(Error::ResponseError(ResponseContent { status, content, entity }))
300 }
301}
302
303pub async fn revoke_oidc_session(configuration: &configuration::Configuration, ) -> Result<(), Error<RevokeOidcSessionError>> {
305
306 let uri_str = format!("{}/oauth2/sessions/logout", configuration.base_path);
307 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
308
309 if let Some(ref user_agent) = configuration.user_agent {
310 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
311 }
312
313 let req = req_builder.build()?;
314 let resp = configuration.client.execute(req).await?;
315
316 let status = resp.status();
317
318 if !status.is_client_error() && !status.is_server_error() {
319 Ok(())
320 } else {
321 let content = resp.text().await?;
322 let entity: Option<RevokeOidcSessionError> = serde_json::from_str(&content).ok();
323 Err(Error::ResponseError(ResponseContent { status, content, entity }))
324 }
325}
326
327pub async fn set_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<SetOidcDynamicClientError>> {
329 let p_id = id;
331 let p_o_auth2_client = o_auth2_client;
332
333 let uri_str = format!("{}/oauth2/register/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
334 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
335
336 if let Some(ref user_agent) = configuration.user_agent {
337 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
338 }
339 if let Some(ref token) = configuration.bearer_access_token {
340 req_builder = req_builder.bearer_auth(token.to_owned());
341 };
342 req_builder = req_builder.json(&p_o_auth2_client);
343
344 let req = req_builder.build()?;
345 let resp = configuration.client.execute(req).await?;
346
347 let status = resp.status();
348 let content_type = resp
349 .headers()
350 .get("content-type")
351 .and_then(|v| v.to_str().ok())
352 .unwrap_or("application/octet-stream");
353 let content_type = super::ContentType::from(content_type);
354
355 if !status.is_client_error() && !status.is_server_error() {
356 let content = resp.text().await?;
357 match content_type {
358 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
359 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
360 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::OAuth2Client`")))),
361 }
362 } else {
363 let content = resp.text().await?;
364 let entity: Option<SetOidcDynamicClientError> = serde_json::from_str(&content).ok();
365 Err(Error::ResponseError(ResponseContent { status, content, entity }))
366 }
367}
368