Skip to main content

ory_client/apis/
o_auth2_api.rs

1/*
2 * Ory APIs
3 *
4 * # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers.  ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages:  | Language       | Download SDK                                                     | Documentation                                                                        | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart           | [pub.dev](https://pub.dev/packages/ory_client)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md)       | | .NET           | [nuget.org](https://www.nuget.org/packages/Ory.Client/)          | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md)     | | Elixir         | [hex.pm](https://hex.pm/packages/ory_client)                     | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md)     | | Go             | [github.com](https://github.com/ory/client-go)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md)         | | Java           | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md)       | | JavaScript     | [npmjs.com](https://www.npmjs.com/package/@ory/client)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) |  | PHP            | [packagist.org](https://packagist.org/packages/ory/client)       | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md)        | | Python         | [pypi.org](https://pypi.org/project/ory-client/)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md)     | | Ruby           | [rubygems.org](https://rubygems.org/gems/ory-client)             | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md)       | | Rust           | [crates.io](https://crates.io/crates/ory-client)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md)       | 
5 *
6 * The version of the OpenAPI document: v1.22.94
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`accept_o_auth2_consent_request`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AcceptOAuth2ConsentRequestError {
22    DefaultResponse(models::ErrorOAuth2),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`accept_o_auth2_login_request`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum AcceptOAuth2LoginRequestError {
30    DefaultResponse(models::ErrorOAuth2),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`accept_o_auth2_logout_request`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum AcceptOAuth2LogoutRequestError {
38    DefaultResponse(models::ErrorOAuth2),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`accept_user_code_request`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum AcceptUserCodeRequestError {
46    DefaultResponse(models::ErrorOAuth2),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`create_o_auth2_client`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum CreateOAuth2ClientError {
54    Status400(models::ErrorOAuth2),
55    DefaultResponse(models::ErrorOAuth2),
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`delete_o_auth2_client`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum DeleteOAuth2ClientError {
63    DefaultResponse(models::GenericError),
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`delete_o_auth2_token`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum DeleteOAuth2TokenError {
71    DefaultResponse(models::ErrorOAuth2),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`delete_rotated_o_auth2_client_secrets`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum DeleteRotatedOAuth2ClientSecretsError {
79    Status404(models::ErrorOAuth2),
80    DefaultResponse(models::ErrorOAuth2),
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`delete_trusted_o_auth2_jwt_grant_issuer`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum DeleteTrustedOAuth2JwtGrantIssuerError {
88    DefaultResponse(models::GenericError),
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method [`get_o_auth2_client`]
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum GetOAuth2ClientError {
96    DefaultResponse(models::ErrorOAuth2),
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`get_o_auth2_consent_request`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum GetOAuth2ConsentRequestError {
104    Status410(models::OAuth2RedirectTo),
105    DefaultResponse(models::ErrorOAuth2),
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`get_o_auth2_login_request`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum GetOAuth2LoginRequestError {
113    Status410(models::OAuth2RedirectTo),
114    DefaultResponse(models::ErrorOAuth2),
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`get_o_auth2_logout_request`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum GetOAuth2LogoutRequestError {
122    DefaultResponse(models::ErrorOAuth2),
123    UnknownValue(serde_json::Value),
124}
125
126/// struct for typed errors of method [`get_trusted_o_auth2_jwt_grant_issuer`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum GetTrustedOAuth2JwtGrantIssuerError {
130    DefaultResponse(models::GenericError),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`introspect_o_auth2_token`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum IntrospectOAuth2TokenError {
138    DefaultResponse(models::ErrorOAuth2),
139    UnknownValue(serde_json::Value),
140}
141
142/// struct for typed errors of method [`list_o_auth2_clients`]
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum ListOAuth2ClientsError {
146    DefaultResponse(models::ErrorOAuth2),
147    UnknownValue(serde_json::Value),
148}
149
150/// struct for typed errors of method [`list_o_auth2_consent_sessions`]
151#[derive(Debug, Clone, Serialize, Deserialize)]
152#[serde(untagged)]
153pub enum ListOAuth2ConsentSessionsError {
154    DefaultResponse(models::ErrorOAuth2),
155    UnknownValue(serde_json::Value),
156}
157
158/// struct for typed errors of method [`list_trusted_o_auth2_jwt_grant_issuers`]
159#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum ListTrustedOAuth2JwtGrantIssuersError {
162    DefaultResponse(models::GenericError),
163    UnknownValue(serde_json::Value),
164}
165
166/// struct for typed errors of method [`o_auth2_authorize`]
167#[derive(Debug, Clone, Serialize, Deserialize)]
168#[serde(untagged)]
169pub enum OAuth2AuthorizeError {
170    DefaultResponse(models::ErrorOAuth2),
171    UnknownValue(serde_json::Value),
172}
173
174/// struct for typed errors of method [`o_auth2_device_flow`]
175#[derive(Debug, Clone, Serialize, Deserialize)]
176#[serde(untagged)]
177pub enum OAuth2DeviceFlowError {
178    DefaultResponse(models::ErrorOAuth2),
179    UnknownValue(serde_json::Value),
180}
181
182/// struct for typed errors of method [`oauth2_token_exchange`]
183#[derive(Debug, Clone, Serialize, Deserialize)]
184#[serde(untagged)]
185pub enum Oauth2TokenExchangeError {
186    DefaultResponse(models::ErrorOAuth2),
187    UnknownValue(serde_json::Value),
188}
189
190/// struct for typed errors of method [`patch_o_auth2_client`]
191#[derive(Debug, Clone, Serialize, Deserialize)]
192#[serde(untagged)]
193pub enum PatchOAuth2ClientError {
194    Status404(models::ErrorOAuth2),
195    DefaultResponse(models::ErrorOAuth2),
196    UnknownValue(serde_json::Value),
197}
198
199/// struct for typed errors of method [`perform_o_auth2_device_verification_flow`]
200#[derive(Debug, Clone, Serialize, Deserialize)]
201#[serde(untagged)]
202pub enum PerformOAuth2DeviceVerificationFlowError {
203    DefaultResponse(models::ErrorOAuth2),
204    UnknownValue(serde_json::Value),
205}
206
207/// struct for typed errors of method [`reject_o_auth2_consent_request`]
208#[derive(Debug, Clone, Serialize, Deserialize)]
209#[serde(untagged)]
210pub enum RejectOAuth2ConsentRequestError {
211    DefaultResponse(models::ErrorOAuth2),
212    UnknownValue(serde_json::Value),
213}
214
215/// struct for typed errors of method [`reject_o_auth2_login_request`]
216#[derive(Debug, Clone, Serialize, Deserialize)]
217#[serde(untagged)]
218pub enum RejectOAuth2LoginRequestError {
219    DefaultResponse(models::ErrorOAuth2),
220    UnknownValue(serde_json::Value),
221}
222
223/// struct for typed errors of method [`reject_o_auth2_logout_request`]
224#[derive(Debug, Clone, Serialize, Deserialize)]
225#[serde(untagged)]
226pub enum RejectOAuth2LogoutRequestError {
227    DefaultResponse(models::ErrorOAuth2),
228    UnknownValue(serde_json::Value),
229}
230
231/// struct for typed errors of method [`revoke_o_auth2_consent_sessions`]
232#[derive(Debug, Clone, Serialize, Deserialize)]
233#[serde(untagged)]
234pub enum RevokeOAuth2ConsentSessionsError {
235    DefaultResponse(models::ErrorOAuth2),
236    UnknownValue(serde_json::Value),
237}
238
239/// struct for typed errors of method [`revoke_o_auth2_login_sessions`]
240#[derive(Debug, Clone, Serialize, Deserialize)]
241#[serde(untagged)]
242pub enum RevokeOAuth2LoginSessionsError {
243    DefaultResponse(models::ErrorOAuth2),
244    UnknownValue(serde_json::Value),
245}
246
247/// struct for typed errors of method [`revoke_o_auth2_token`]
248#[derive(Debug, Clone, Serialize, Deserialize)]
249#[serde(untagged)]
250pub enum RevokeOAuth2TokenError {
251    DefaultResponse(models::ErrorOAuth2),
252    UnknownValue(serde_json::Value),
253}
254
255/// struct for typed errors of method [`rotate_o_auth2_client_secret`]
256#[derive(Debug, Clone, Serialize, Deserialize)]
257#[serde(untagged)]
258pub enum RotateOAuth2ClientSecretError {
259    Status400(models::ErrorOAuth2),
260    Status404(models::ErrorOAuth2),
261    DefaultResponse(models::ErrorOAuth2),
262    UnknownValue(serde_json::Value),
263}
264
265/// struct for typed errors of method [`set_o_auth2_client`]
266#[derive(Debug, Clone, Serialize, Deserialize)]
267#[serde(untagged)]
268pub enum SetOAuth2ClientError {
269    Status400(models::ErrorOAuth2),
270    Status404(models::ErrorOAuth2),
271    DefaultResponse(models::ErrorOAuth2),
272    UnknownValue(serde_json::Value),
273}
274
275/// struct for typed errors of method [`set_o_auth2_client_lifespans`]
276#[derive(Debug, Clone, Serialize, Deserialize)]
277#[serde(untagged)]
278pub enum SetOAuth2ClientLifespansError {
279    DefaultResponse(models::GenericError),
280    UnknownValue(serde_json::Value),
281}
282
283/// struct for typed errors of method [`trust_o_auth2_jwt_grant_issuer`]
284#[derive(Debug, Clone, Serialize, Deserialize)]
285#[serde(untagged)]
286pub enum TrustOAuth2JwtGrantIssuerError {
287    DefaultResponse(models::GenericError),
288    UnknownValue(serde_json::Value),
289}
290
291
292/// When an authorization code, hybrid, or implicit OAuth 2.0 Flow is initiated, Ory asks the login provider to authenticate the subject and then tell Ory now about it. If the subject authenticated, he/she must now be asked if the OAuth 2.0 Client which initiated the flow should be allowed to access the resources on the subject's behalf.  The consent challenge is appended to the consent provider's URL to which the subject's user-agent (browser) is redirected to. The consent provider uses that challenge to fetch information on the OAuth2 request and then tells Ory if the subject accepted or rejected the request.  This endpoint tells Ory that the subject has authorized the OAuth 2.0 client to access resources on his/her behalf. The consent provider includes additional information, such as session data for access and ID tokens, and if the consent request should be used as basis for future requests.  The response contains a redirect URL which the consent provider should redirect the user-agent to.  The default consent provider is available via the Ory Managed Account Experience. To customize the consent provider, please head over to the OAuth 2.0 documentation.
293pub async fn accept_o_auth2_consent_request(configuration: &configuration::Configuration, consent_challenge: &str, accept_o_auth2_consent_request: Option<models::AcceptOAuth2ConsentRequest>) -> Result<models::OAuth2RedirectTo, Error<AcceptOAuth2ConsentRequestError>> {
294    // add a prefix to parameters to efficiently prevent name collisions
295    let p_query_consent_challenge = consent_challenge;
296    let p_body_accept_o_auth2_consent_request = accept_o_auth2_consent_request;
297
298    let uri_str = format!("{}/admin/oauth2/auth/requests/consent/accept", configuration.base_path);
299    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
300
301    req_builder = req_builder.query(&[("consent_challenge", &p_query_consent_challenge.to_string())]);
302    if let Some(ref user_agent) = configuration.user_agent {
303        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
304    }
305    if let Some(ref token) = configuration.bearer_access_token {
306        req_builder = req_builder.bearer_auth(token.to_owned());
307    };
308    req_builder = req_builder.json(&p_body_accept_o_auth2_consent_request);
309
310    let req = req_builder.build()?;
311    let resp = configuration.client.execute(req).await?;
312
313    let status = resp.status();
314    let content_type = resp
315        .headers()
316        .get("content-type")
317        .and_then(|v| v.to_str().ok())
318        .unwrap_or("application/octet-stream");
319    let content_type = super::ContentType::from(content_type);
320
321    if !status.is_client_error() && !status.is_server_error() {
322        let content = resp.text().await?;
323        match content_type {
324            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
325            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
326            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::OAuth2RedirectTo`")))),
327        }
328    } else {
329        let content = resp.text().await?;
330        let entity: Option<AcceptOAuth2ConsentRequestError> = serde_json::from_str(&content).ok();
331        Err(Error::ResponseError(ResponseContent { status, content, entity }))
332    }
333}
334
335/// When an authorization code, hybrid, or implicit OAuth 2.0 Flow is initiated, Ory asks the login provider to authenticate the subject and then tell the Ory OAuth2 Service about it.  The authentication challenge is appended to the login provider URL to which the subject's user-agent (browser) is redirected to. The login provider uses that challenge to fetch information on the OAuth2 request and then accept or reject the requested authentication process.  This endpoint tells Ory that the subject has successfully authenticated and includes additional information such as the subject's ID and if Ory should remember the subject's subject agent for future authentication attempts by setting a cookie.  The response contains a redirect URL which the login provider should redirect the user-agent to.
336pub async fn accept_o_auth2_login_request(configuration: &configuration::Configuration, login_challenge: &str, accept_o_auth2_login_request: Option<models::AcceptOAuth2LoginRequest>) -> Result<models::OAuth2RedirectTo, Error<AcceptOAuth2LoginRequestError>> {
337    // add a prefix to parameters to efficiently prevent name collisions
338    let p_query_login_challenge = login_challenge;
339    let p_body_accept_o_auth2_login_request = accept_o_auth2_login_request;
340
341    let uri_str = format!("{}/admin/oauth2/auth/requests/login/accept", configuration.base_path);
342    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
343
344    req_builder = req_builder.query(&[("login_challenge", &p_query_login_challenge.to_string())]);
345    if let Some(ref user_agent) = configuration.user_agent {
346        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
347    }
348    if let Some(ref token) = configuration.bearer_access_token {
349        req_builder = req_builder.bearer_auth(token.to_owned());
350    };
351    req_builder = req_builder.json(&p_body_accept_o_auth2_login_request);
352
353    let req = req_builder.build()?;
354    let resp = configuration.client.execute(req).await?;
355
356    let status = resp.status();
357    let content_type = resp
358        .headers()
359        .get("content-type")
360        .and_then(|v| v.to_str().ok())
361        .unwrap_or("application/octet-stream");
362    let content_type = super::ContentType::from(content_type);
363
364    if !status.is_client_error() && !status.is_server_error() {
365        let content = resp.text().await?;
366        match content_type {
367            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
368            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
369            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::OAuth2RedirectTo`")))),
370        }
371    } else {
372        let content = resp.text().await?;
373        let entity: Option<AcceptOAuth2LoginRequestError> = serde_json::from_str(&content).ok();
374        Err(Error::ResponseError(ResponseContent { status, content, entity }))
375    }
376}
377
378/// When a user or an application requests Ory OAuth 2.0 to remove the session state of a subject, this endpoint is used to confirm that logout request.  The response contains a redirect URL which the consent provider should redirect the user-agent to.
379pub async fn accept_o_auth2_logout_request(configuration: &configuration::Configuration, logout_challenge: &str) -> Result<models::OAuth2RedirectTo, Error<AcceptOAuth2LogoutRequestError>> {
380    // add a prefix to parameters to efficiently prevent name collisions
381    let p_query_logout_challenge = logout_challenge;
382
383    let uri_str = format!("{}/admin/oauth2/auth/requests/logout/accept", configuration.base_path);
384    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
385
386    req_builder = req_builder.query(&[("logout_challenge", &p_query_logout_challenge.to_string())]);
387    if let Some(ref user_agent) = configuration.user_agent {
388        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
389    }
390    if let Some(ref token) = configuration.bearer_access_token {
391        req_builder = req_builder.bearer_auth(token.to_owned());
392    };
393
394    let req = req_builder.build()?;
395    let resp = configuration.client.execute(req).await?;
396
397    let status = resp.status();
398    let content_type = resp
399        .headers()
400        .get("content-type")
401        .and_then(|v| v.to_str().ok())
402        .unwrap_or("application/octet-stream");
403    let content_type = super::ContentType::from(content_type);
404
405    if !status.is_client_error() && !status.is_server_error() {
406        let content = resp.text().await?;
407        match content_type {
408            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
409            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
410            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::OAuth2RedirectTo`")))),
411        }
412    } else {
413        let content = resp.text().await?;
414        let entity: Option<AcceptOAuth2LogoutRequestError> = serde_json::from_str(&content).ok();
415        Err(Error::ResponseError(ResponseContent { status, content, entity }))
416    }
417}
418
419/// Accepts a device grant user_code request
420pub async fn accept_user_code_request(configuration: &configuration::Configuration, device_challenge: &str, accept_device_user_code_request: Option<models::AcceptDeviceUserCodeRequest>) -> Result<models::OAuth2RedirectTo, Error<AcceptUserCodeRequestError>> {
421    // add a prefix to parameters to efficiently prevent name collisions
422    let p_query_device_challenge = device_challenge;
423    let p_body_accept_device_user_code_request = accept_device_user_code_request;
424
425    let uri_str = format!("{}/admin/oauth2/auth/requests/device/accept", configuration.base_path);
426    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
427
428    req_builder = req_builder.query(&[("device_challenge", &p_query_device_challenge.to_string())]);
429    if let Some(ref user_agent) = configuration.user_agent {
430        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
431    }
432    if let Some(ref token) = configuration.bearer_access_token {
433        req_builder = req_builder.bearer_auth(token.to_owned());
434    };
435    req_builder = req_builder.json(&p_body_accept_device_user_code_request);
436
437    let req = req_builder.build()?;
438    let resp = configuration.client.execute(req).await?;
439
440    let status = resp.status();
441    let content_type = resp
442        .headers()
443        .get("content-type")
444        .and_then(|v| v.to_str().ok())
445        .unwrap_or("application/octet-stream");
446    let content_type = super::ContentType::from(content_type);
447
448    if !status.is_client_error() && !status.is_server_error() {
449        let content = resp.text().await?;
450        match content_type {
451            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
452            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
453            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::OAuth2RedirectTo`")))),
454        }
455    } else {
456        let content = resp.text().await?;
457        let entity: Option<AcceptUserCodeRequestError> = serde_json::from_str(&content).ok();
458        Err(Error::ResponseError(ResponseContent { status, content, entity }))
459    }
460}
461
462/// Create a new OAuth 2.0 client. If you pass `client_secret` the secret is used, otherwise a random secret is generated. The secret is echoed in the response. It is not possible to retrieve it later on.
463pub async fn create_o_auth2_client(configuration: &configuration::Configuration, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<CreateOAuth2ClientError>> {
464    // add a prefix to parameters to efficiently prevent name collisions
465    let p_body_o_auth2_client = o_auth2_client;
466
467    let uri_str = format!("{}/admin/clients", configuration.base_path);
468    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
469
470    if let Some(ref user_agent) = configuration.user_agent {
471        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
472    }
473    if let Some(ref token) = configuration.bearer_access_token {
474        req_builder = req_builder.bearer_auth(token.to_owned());
475    };
476    req_builder = req_builder.json(&p_body_o_auth2_client);
477
478    let req = req_builder.build()?;
479    let resp = configuration.client.execute(req).await?;
480
481    let status = resp.status();
482    let content_type = resp
483        .headers()
484        .get("content-type")
485        .and_then(|v| v.to_str().ok())
486        .unwrap_or("application/octet-stream");
487    let content_type = super::ContentType::from(content_type);
488
489    if !status.is_client_error() && !status.is_server_error() {
490        let content = resp.text().await?;
491        match content_type {
492            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
493            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
494            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`")))),
495        }
496    } else {
497        let content = resp.text().await?;
498        let entity: Option<CreateOAuth2ClientError> = serde_json::from_str(&content).ok();
499        Err(Error::ResponseError(ResponseContent { status, content, entity }))
500    }
501}
502
503/// Delete an existing OAuth 2.0 Client by its ID.  OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.  Make sure that this endpoint is well protected and only callable by first-party components.
504pub async fn delete_o_auth2_client(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteOAuth2ClientError>> {
505    // add a prefix to parameters to efficiently prevent name collisions
506    let p_path_id = id;
507
508    let uri_str = format!("{}/admin/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
509    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
510
511    if let Some(ref user_agent) = configuration.user_agent {
512        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
513    }
514    if let Some(ref token) = configuration.bearer_access_token {
515        req_builder = req_builder.bearer_auth(token.to_owned());
516    };
517
518    let req = req_builder.build()?;
519    let resp = configuration.client.execute(req).await?;
520
521    let status = resp.status();
522
523    if !status.is_client_error() && !status.is_server_error() {
524        Ok(())
525    } else {
526        let content = resp.text().await?;
527        let entity: Option<DeleteOAuth2ClientError> = serde_json::from_str(&content).ok();
528        Err(Error::ResponseError(ResponseContent { status, content, entity }))
529    }
530}
531
532/// This endpoint deletes OAuth2 access tokens issued to an OAuth 2.0 Client from the database.
533pub async fn delete_o_auth2_token(configuration: &configuration::Configuration, client_id: &str) -> Result<(), Error<DeleteOAuth2TokenError>> {
534    // add a prefix to parameters to efficiently prevent name collisions
535    let p_query_client_id = client_id;
536
537    let uri_str = format!("{}/admin/oauth2/tokens", configuration.base_path);
538    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
539
540    req_builder = req_builder.query(&[("client_id", &p_query_client_id.to_string())]);
541    if let Some(ref user_agent) = configuration.user_agent {
542        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
543    }
544    if let Some(ref token) = configuration.bearer_access_token {
545        req_builder = req_builder.bearer_auth(token.to_owned());
546    };
547
548    let req = req_builder.build()?;
549    let resp = configuration.client.execute(req).await?;
550
551    let status = resp.status();
552
553    if !status.is_client_error() && !status.is_server_error() {
554        Ok(())
555    } else {
556        let content = resp.text().await?;
557        let entity: Option<DeleteOAuth2TokenError> = serde_json::from_str(&content).ok();
558        Err(Error::ResponseError(ResponseContent { status, content, entity }))
559    }
560}
561
562/// Removes all rotated secrets from an OAuth 2.0 client. This should be called after all services have been updated to use the new secret and the old secrets are no longer needed.
563pub async fn delete_rotated_o_auth2_client_secrets(configuration: &configuration::Configuration, id: &str) -> Result<models::OAuth2Client, Error<DeleteRotatedOAuth2ClientSecretsError>> {
564    // add a prefix to parameters to efficiently prevent name collisions
565    let p_path_id = id;
566
567    let uri_str = format!("{}/admin/clients/{id}/secrets/rotate", configuration.base_path, id=crate::apis::urlencode(p_path_id));
568    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
569
570    if let Some(ref user_agent) = configuration.user_agent {
571        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
572    }
573    if let Some(ref token) = configuration.bearer_access_token {
574        req_builder = req_builder.bearer_auth(token.to_owned());
575    };
576
577    let req = req_builder.build()?;
578    let resp = configuration.client.execute(req).await?;
579
580    let status = resp.status();
581    let content_type = resp
582        .headers()
583        .get("content-type")
584        .and_then(|v| v.to_str().ok())
585        .unwrap_or("application/octet-stream");
586    let content_type = super::ContentType::from(content_type);
587
588    if !status.is_client_error() && !status.is_server_error() {
589        let content = resp.text().await?;
590        match content_type {
591            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
592            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
593            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`")))),
594        }
595    } else {
596        let content = resp.text().await?;
597        let entity: Option<DeleteRotatedOAuth2ClientSecretsError> = serde_json::from_str(&content).ok();
598        Err(Error::ResponseError(ResponseContent { status, content, entity }))
599    }
600}
601
602/// Use this endpoint to delete trusted JWT Bearer Grant Type Issuer. The ID is the one returned when you created the trust relationship.  Once deleted, the associated issuer will no longer be able to perform the JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grant.
603pub async fn delete_trusted_o_auth2_jwt_grant_issuer(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteTrustedOAuth2JwtGrantIssuerError>> {
604    // add a prefix to parameters to efficiently prevent name collisions
605    let p_path_id = id;
606
607    let uri_str = format!("{}/admin/trust/grants/jwt-bearer/issuers/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
608    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
609
610    if let Some(ref user_agent) = configuration.user_agent {
611        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
612    }
613    if let Some(ref token) = configuration.bearer_access_token {
614        req_builder = req_builder.bearer_auth(token.to_owned());
615    };
616
617    let req = req_builder.build()?;
618    let resp = configuration.client.execute(req).await?;
619
620    let status = resp.status();
621
622    if !status.is_client_error() && !status.is_server_error() {
623        Ok(())
624    } else {
625        let content = resp.text().await?;
626        let entity: Option<DeleteTrustedOAuth2JwtGrantIssuerError> = serde_json::from_str(&content).ok();
627        Err(Error::ResponseError(ResponseContent { status, content, entity }))
628    }
629}
630
631/// Get an OAuth 2.0 client by its ID. This endpoint never returns the client secret.  OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.
632pub async fn get_o_auth2_client(configuration: &configuration::Configuration, id: &str) -> Result<models::OAuth2Client, Error<GetOAuth2ClientError>> {
633    // add a prefix to parameters to efficiently prevent name collisions
634    let p_path_id = id;
635
636    let uri_str = format!("{}/admin/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
637    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
638
639    if let Some(ref user_agent) = configuration.user_agent {
640        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
641    }
642    if let Some(ref token) = configuration.bearer_access_token {
643        req_builder = req_builder.bearer_auth(token.to_owned());
644    };
645
646    let req = req_builder.build()?;
647    let resp = configuration.client.execute(req).await?;
648
649    let status = resp.status();
650    let content_type = resp
651        .headers()
652        .get("content-type")
653        .and_then(|v| v.to_str().ok())
654        .unwrap_or("application/octet-stream");
655    let content_type = super::ContentType::from(content_type);
656
657    if !status.is_client_error() && !status.is_server_error() {
658        let content = resp.text().await?;
659        match content_type {
660            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
661            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
662            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`")))),
663        }
664    } else {
665        let content = resp.text().await?;
666        let entity: Option<GetOAuth2ClientError> = serde_json::from_str(&content).ok();
667        Err(Error::ResponseError(ResponseContent { status, content, entity }))
668    }
669}
670
671/// When an authorization code, hybrid, or implicit OAuth 2.0 Flow is initiated, Ory asks the login provider to authenticate the subject and then tell Ory now about it. If the subject authenticated, he/she must now be asked if the OAuth 2.0 Client which initiated the flow should be allowed to access the resources on the subject's behalf.  The consent challenge is appended to the consent provider's URL to which the subject's user-agent (browser) is redirected to. The consent provider uses that challenge to fetch information on the OAuth2 request and then tells Ory if the subject accepted or rejected the request.  The default consent provider is available via the Ory Managed Account Experience. To customize the consent provider, please head over to the OAuth 2.0 documentation.
672pub async fn get_o_auth2_consent_request(configuration: &configuration::Configuration, consent_challenge: &str) -> Result<models::OAuth2ConsentRequest, Error<GetOAuth2ConsentRequestError>> {
673    // add a prefix to parameters to efficiently prevent name collisions
674    let p_query_consent_challenge = consent_challenge;
675
676    let uri_str = format!("{}/admin/oauth2/auth/requests/consent", configuration.base_path);
677    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
678
679    req_builder = req_builder.query(&[("consent_challenge", &p_query_consent_challenge.to_string())]);
680    if let Some(ref user_agent) = configuration.user_agent {
681        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
682    }
683    if let Some(ref token) = configuration.bearer_access_token {
684        req_builder = req_builder.bearer_auth(token.to_owned());
685    };
686
687    let req = req_builder.build()?;
688    let resp = configuration.client.execute(req).await?;
689
690    let status = resp.status();
691    let content_type = resp
692        .headers()
693        .get("content-type")
694        .and_then(|v| v.to_str().ok())
695        .unwrap_or("application/octet-stream");
696    let content_type = super::ContentType::from(content_type);
697
698    if !status.is_client_error() && !status.is_server_error() {
699        let content = resp.text().await?;
700        match content_type {
701            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
702            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2ConsentRequest`"))),
703            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::OAuth2ConsentRequest`")))),
704        }
705    } else {
706        let content = resp.text().await?;
707        let entity: Option<GetOAuth2ConsentRequestError> = serde_json::from_str(&content).ok();
708        Err(Error::ResponseError(ResponseContent { status, content, entity }))
709    }
710}
711
712/// When an authorization code, hybrid, or implicit OAuth 2.0 Flow is initiated, Ory asks the login provider to authenticate the subject and then tell the Ory OAuth2 Service about it.  Per default, the login provider is Ory itself. You may use a different login provider which needs to be a web-app you write and host, and it must be able to authenticate (\"show the subject a login screen\") a subject (in OAuth2 the proper name for subject is \"resource owner\").  The authentication challenge is appended to the login provider URL to which the subject's user-agent (browser) is redirected to. The login provider uses that challenge to fetch information on the OAuth2 request and then accept or reject the requested authentication process.
713pub async fn get_o_auth2_login_request(configuration: &configuration::Configuration, login_challenge: &str) -> Result<models::OAuth2LoginRequest, Error<GetOAuth2LoginRequestError>> {
714    // add a prefix to parameters to efficiently prevent name collisions
715    let p_query_login_challenge = login_challenge;
716
717    let uri_str = format!("{}/admin/oauth2/auth/requests/login", configuration.base_path);
718    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
719
720    req_builder = req_builder.query(&[("login_challenge", &p_query_login_challenge.to_string())]);
721    if let Some(ref user_agent) = configuration.user_agent {
722        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
723    }
724    if let Some(ref token) = configuration.bearer_access_token {
725        req_builder = req_builder.bearer_auth(token.to_owned());
726    };
727
728    let req = req_builder.build()?;
729    let resp = configuration.client.execute(req).await?;
730
731    let status = resp.status();
732    let content_type = resp
733        .headers()
734        .get("content-type")
735        .and_then(|v| v.to_str().ok())
736        .unwrap_or("application/octet-stream");
737    let content_type = super::ContentType::from(content_type);
738
739    if !status.is_client_error() && !status.is_server_error() {
740        let content = resp.text().await?;
741        match content_type {
742            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
743            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2LoginRequest`"))),
744            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::OAuth2LoginRequest`")))),
745        }
746    } else {
747        let content = resp.text().await?;
748        let entity: Option<GetOAuth2LoginRequestError> = serde_json::from_str(&content).ok();
749        Err(Error::ResponseError(ResponseContent { status, content, entity }))
750    }
751}
752
753/// Use this endpoint to fetch an Ory OAuth 2.0 logout request.
754pub async fn get_o_auth2_logout_request(configuration: &configuration::Configuration, logout_challenge: &str) -> Result<models::OAuth2LogoutRequest, Error<GetOAuth2LogoutRequestError>> {
755    // add a prefix to parameters to efficiently prevent name collisions
756    let p_query_logout_challenge = logout_challenge;
757
758    let uri_str = format!("{}/admin/oauth2/auth/requests/logout", configuration.base_path);
759    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
760
761    req_builder = req_builder.query(&[("logout_challenge", &p_query_logout_challenge.to_string())]);
762    if let Some(ref user_agent) = configuration.user_agent {
763        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
764    }
765    if let Some(ref token) = configuration.bearer_access_token {
766        req_builder = req_builder.bearer_auth(token.to_owned());
767    };
768
769    let req = req_builder.build()?;
770    let resp = configuration.client.execute(req).await?;
771
772    let status = resp.status();
773    let content_type = resp
774        .headers()
775        .get("content-type")
776        .and_then(|v| v.to_str().ok())
777        .unwrap_or("application/octet-stream");
778    let content_type = super::ContentType::from(content_type);
779
780    if !status.is_client_error() && !status.is_server_error() {
781        let content = resp.text().await?;
782        match content_type {
783            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
784            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2LogoutRequest`"))),
785            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::OAuth2LogoutRequest`")))),
786        }
787    } else {
788        let content = resp.text().await?;
789        let entity: Option<GetOAuth2LogoutRequestError> = serde_json::from_str(&content).ok();
790        Err(Error::ResponseError(ResponseContent { status, content, entity }))
791    }
792}
793
794/// Use this endpoint to get a trusted JWT Bearer Grant Type Issuer. The ID is the one returned when you created the trust relationship.
795pub async fn get_trusted_o_auth2_jwt_grant_issuer(configuration: &configuration::Configuration, id: &str) -> Result<models::TrustedOAuth2JwtGrantIssuer, Error<GetTrustedOAuth2JwtGrantIssuerError>> {
796    // add a prefix to parameters to efficiently prevent name collisions
797    let p_path_id = id;
798
799    let uri_str = format!("{}/admin/trust/grants/jwt-bearer/issuers/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
800    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
801
802    if let Some(ref user_agent) = configuration.user_agent {
803        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
804    }
805    if let Some(ref token) = configuration.bearer_access_token {
806        req_builder = req_builder.bearer_auth(token.to_owned());
807    };
808
809    let req = req_builder.build()?;
810    let resp = configuration.client.execute(req).await?;
811
812    let status = resp.status();
813    let content_type = resp
814        .headers()
815        .get("content-type")
816        .and_then(|v| v.to_str().ok())
817        .unwrap_or("application/octet-stream");
818    let content_type = super::ContentType::from(content_type);
819
820    if !status.is_client_error() && !status.is_server_error() {
821        let content = resp.text().await?;
822        match content_type {
823            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
824            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrustedOAuth2JwtGrantIssuer`"))),
825            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::TrustedOAuth2JwtGrantIssuer`")))),
826        }
827    } else {
828        let content = resp.text().await?;
829        let entity: Option<GetTrustedOAuth2JwtGrantIssuerError> = serde_json::from_str(&content).ok();
830        Err(Error::ResponseError(ResponseContent { status, content, entity }))
831    }
832}
833
834/// The introspection endpoint allows to check if a token (both refresh and access) is active or not. An active token is neither expired nor revoked. If a token is active, additional information on the token will be included. You can set additional data for a token by setting `session.access_token` during the consent flow.
835pub async fn introspect_o_auth2_token(configuration: &configuration::Configuration, token: &str, scope: Option<&str>) -> Result<models::IntrospectedOAuth2Token, Error<IntrospectOAuth2TokenError>> {
836    // add a prefix to parameters to efficiently prevent name collisions
837    let p_form_token = token;
838    let p_form_scope = scope;
839
840    let uri_str = format!("{}/admin/oauth2/introspect", configuration.base_path);
841    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
842
843    if let Some(ref user_agent) = configuration.user_agent {
844        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
845    }
846    if let Some(ref token) = configuration.bearer_access_token {
847        req_builder = req_builder.bearer_auth(token.to_owned());
848    };
849    let mut multipart_form_params = std::collections::HashMap::new();
850    if let Some(param_value) = p_form_scope {
851        multipart_form_params.insert("scope", param_value.to_string());
852    }
853    multipart_form_params.insert("token", p_form_token.to_string());
854    req_builder = req_builder.form(&multipart_form_params);
855
856    let req = req_builder.build()?;
857    let resp = configuration.client.execute(req).await?;
858
859    let status = resp.status();
860    let content_type = resp
861        .headers()
862        .get("content-type")
863        .and_then(|v| v.to_str().ok())
864        .unwrap_or("application/octet-stream");
865    let content_type = super::ContentType::from(content_type);
866
867    if !status.is_client_error() && !status.is_server_error() {
868        let content = resp.text().await?;
869        match content_type {
870            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
871            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IntrospectedOAuth2Token`"))),
872            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::IntrospectedOAuth2Token`")))),
873        }
874    } else {
875        let content = resp.text().await?;
876        let entity: Option<IntrospectOAuth2TokenError> = serde_json::from_str(&content).ok();
877        Err(Error::ResponseError(ResponseContent { status, content, entity }))
878    }
879}
880
881/// This endpoint lists all clients in the database, and never returns client secrets. As a default it lists the first 100 clients.
882pub async fn list_o_auth2_clients(configuration: &configuration::Configuration, page_size: Option<i64>, page_token: Option<&str>, client_name: Option<&str>, owner: Option<&str>) -> Result<Vec<models::OAuth2Client>, Error<ListOAuth2ClientsError>> {
883    // add a prefix to parameters to efficiently prevent name collisions
884    let p_query_page_size = page_size;
885    let p_query_page_token = page_token;
886    let p_query_client_name = client_name;
887    let p_query_owner = owner;
888
889    let uri_str = format!("{}/admin/clients", configuration.base_path);
890    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
891
892    if let Some(ref param_value) = p_query_page_size {
893        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
894    }
895    if let Some(ref param_value) = p_query_page_token {
896        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
897    }
898    if let Some(ref param_value) = p_query_client_name {
899        req_builder = req_builder.query(&[("client_name", &param_value.to_string())]);
900    }
901    if let Some(ref param_value) = p_query_owner {
902        req_builder = req_builder.query(&[("owner", &param_value.to_string())]);
903    }
904    if let Some(ref user_agent) = configuration.user_agent {
905        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
906    }
907    if let Some(ref token) = configuration.bearer_access_token {
908        req_builder = req_builder.bearer_auth(token.to_owned());
909    };
910
911    let req = req_builder.build()?;
912    let resp = configuration.client.execute(req).await?;
913
914    let status = resp.status();
915    let content_type = resp
916        .headers()
917        .get("content-type")
918        .and_then(|v| v.to_str().ok())
919        .unwrap_or("application/octet-stream");
920    let content_type = super::ContentType::from(content_type);
921
922    if !status.is_client_error() && !status.is_server_error() {
923        let content = resp.text().await?;
924        match content_type {
925            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
926            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OAuth2Client&gt;`"))),
927            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::OAuth2Client&gt;`")))),
928        }
929    } else {
930        let content = resp.text().await?;
931        let entity: Option<ListOAuth2ClientsError> = serde_json::from_str(&content).ok();
932        Err(Error::ResponseError(ResponseContent { status, content, entity }))
933    }
934}
935
936/// This endpoint lists all subject's granted consent sessions, including client and granted scope. If the subject is unknown or has not granted any consent sessions yet, the endpoint returns an empty JSON array with status code 200 OK.
937pub async fn list_o_auth2_consent_sessions(configuration: &configuration::Configuration, subject: &str, page_size: Option<i64>, page_token: Option<&str>, login_session_id: Option<&str>) -> Result<Vec<models::OAuth2ConsentSession>, Error<ListOAuth2ConsentSessionsError>> {
938    // add a prefix to parameters to efficiently prevent name collisions
939    let p_query_subject = subject;
940    let p_query_page_size = page_size;
941    let p_query_page_token = page_token;
942    let p_query_login_session_id = login_session_id;
943
944    let uri_str = format!("{}/admin/oauth2/auth/sessions/consent", configuration.base_path);
945    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
946
947    if let Some(ref param_value) = p_query_page_size {
948        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
949    }
950    if let Some(ref param_value) = p_query_page_token {
951        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
952    }
953    req_builder = req_builder.query(&[("subject", &p_query_subject.to_string())]);
954    if let Some(ref param_value) = p_query_login_session_id {
955        req_builder = req_builder.query(&[("login_session_id", &param_value.to_string())]);
956    }
957    if let Some(ref user_agent) = configuration.user_agent {
958        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
959    }
960    if let Some(ref token) = configuration.bearer_access_token {
961        req_builder = req_builder.bearer_auth(token.to_owned());
962    };
963
964    let req = req_builder.build()?;
965    let resp = configuration.client.execute(req).await?;
966
967    let status = resp.status();
968    let content_type = resp
969        .headers()
970        .get("content-type")
971        .and_then(|v| v.to_str().ok())
972        .unwrap_or("application/octet-stream");
973    let content_type = super::ContentType::from(content_type);
974
975    if !status.is_client_error() && !status.is_server_error() {
976        let content = resp.text().await?;
977        match content_type {
978            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
979            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OAuth2ConsentSession&gt;`"))),
980            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::OAuth2ConsentSession&gt;`")))),
981        }
982    } else {
983        let content = resp.text().await?;
984        let entity: Option<ListOAuth2ConsentSessionsError> = serde_json::from_str(&content).ok();
985        Err(Error::ResponseError(ResponseContent { status, content, entity }))
986    }
987}
988
989/// Use this endpoint to list all trusted JWT Bearer Grant Type Issuers.
990pub async fn list_trusted_o_auth2_jwt_grant_issuers(configuration: &configuration::Configuration, page_size: Option<i64>, page_token: Option<&str>, issuer: Option<&str>) -> Result<Vec<models::TrustedOAuth2JwtGrantIssuer>, Error<ListTrustedOAuth2JwtGrantIssuersError>> {
991    // add a prefix to parameters to efficiently prevent name collisions
992    let p_query_page_size = page_size;
993    let p_query_page_token = page_token;
994    let p_query_issuer = issuer;
995
996    let uri_str = format!("{}/admin/trust/grants/jwt-bearer/issuers", configuration.base_path);
997    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
998
999    if let Some(ref param_value) = p_query_page_size {
1000        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
1001    }
1002    if let Some(ref param_value) = p_query_page_token {
1003        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
1004    }
1005    if let Some(ref param_value) = p_query_issuer {
1006        req_builder = req_builder.query(&[("issuer", &param_value.to_string())]);
1007    }
1008    if let Some(ref user_agent) = configuration.user_agent {
1009        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1010    }
1011    if let Some(ref token) = configuration.bearer_access_token {
1012        req_builder = req_builder.bearer_auth(token.to_owned());
1013    };
1014
1015    let req = req_builder.build()?;
1016    let resp = configuration.client.execute(req).await?;
1017
1018    let status = resp.status();
1019    let content_type = resp
1020        .headers()
1021        .get("content-type")
1022        .and_then(|v| v.to_str().ok())
1023        .unwrap_or("application/octet-stream");
1024    let content_type = super::ContentType::from(content_type);
1025
1026    if !status.is_client_error() && !status.is_server_error() {
1027        let content = resp.text().await?;
1028        match content_type {
1029            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1030            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::TrustedOAuth2JwtGrantIssuer&gt;`"))),
1031            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::TrustedOAuth2JwtGrantIssuer&gt;`")))),
1032        }
1033    } else {
1034        let content = resp.text().await?;
1035        let entity: Option<ListTrustedOAuth2JwtGrantIssuersError> = serde_json::from_str(&content).ok();
1036        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1037    }
1038}
1039
1040/// Use open source libraries to perform OAuth 2.0 and OpenID Connect available for any programming language. You can find a list of libraries at https://oauth.net/code/  This endpoint should not be used via the Ory SDK and is only included for technical reasons. Instead, use one of the libraries linked above.
1041pub async fn o_auth2_authorize(configuration: &configuration::Configuration, resource: Option<Vec<String>>) -> Result<models::ErrorOAuth2, Error<OAuth2AuthorizeError>> {
1042    // add a prefix to parameters to efficiently prevent name collisions
1043    let p_query_resource = resource;
1044
1045    let uri_str = format!("{}/oauth2/auth", configuration.base_path);
1046    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1047
1048    if let Some(ref param_value) = p_query_resource {
1049        req_builder = match "multi" {
1050            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("resource".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
1051            _ => req_builder.query(&[("resource", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
1052        };
1053    }
1054    if let Some(ref user_agent) = configuration.user_agent {
1055        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1056    }
1057
1058    let req = req_builder.build()?;
1059    let resp = configuration.client.execute(req).await?;
1060
1061    let status = resp.status();
1062    let content_type = resp
1063        .headers()
1064        .get("content-type")
1065        .and_then(|v| v.to_str().ok())
1066        .unwrap_or("application/octet-stream");
1067    let content_type = super::ContentType::from(content_type);
1068
1069    if !status.is_client_error() && !status.is_server_error() {
1070        let content = resp.text().await?;
1071        match content_type {
1072            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1073            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ErrorOAuth2`"))),
1074            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::ErrorOAuth2`")))),
1075        }
1076    } else {
1077        let content = resp.text().await?;
1078        let entity: Option<OAuth2AuthorizeError> = serde_json::from_str(&content).ok();
1079        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1080    }
1081}
1082
1083/// This endpoint is not documented here because you should never use your own implementation to perform OAuth2 flows. OAuth2 is a very popular protocol and a library for your programming language will exist.  To learn more about this flow please refer to the specification: https://tools.ietf.org/html/rfc8628
1084pub async fn o_auth2_device_flow(configuration: &configuration::Configuration, ) -> Result<models::DeviceAuthorization, Error<OAuth2DeviceFlowError>> {
1085
1086    let uri_str = format!("{}/oauth2/device/auth", configuration.base_path);
1087    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1088
1089    if let Some(ref user_agent) = configuration.user_agent {
1090        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1091    }
1092
1093    let req = req_builder.build()?;
1094    let resp = configuration.client.execute(req).await?;
1095
1096    let status = resp.status();
1097    let content_type = resp
1098        .headers()
1099        .get("content-type")
1100        .and_then(|v| v.to_str().ok())
1101        .unwrap_or("application/octet-stream");
1102    let content_type = super::ContentType::from(content_type);
1103
1104    if !status.is_client_error() && !status.is_server_error() {
1105        let content = resp.text().await?;
1106        match content_type {
1107            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1108            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeviceAuthorization`"))),
1109            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::DeviceAuthorization`")))),
1110        }
1111    } else {
1112        let content = resp.text().await?;
1113        let entity: Option<OAuth2DeviceFlowError> = serde_json::from_str(&content).ok();
1114        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1115    }
1116}
1117
1118/// Use open source libraries to perform OAuth 2.0 and OpenID Connect available for any programming language. You can find a list of libraries here https://oauth.net/code/  This endpoint should not be used via the Ory SDK and is only included for technical reasons. Instead, use one of the libraries linked above.
1119pub async fn oauth2_token_exchange(configuration: &configuration::Configuration, grant_type: &str, client_id: Option<&str>, code: Option<&str>, redirect_uri: Option<&str>, refresh_token: Option<&str>, resource: Option<Vec<String>>) -> Result<models::OAuth2TokenExchange, Error<Oauth2TokenExchangeError>> {
1120    // add a prefix to parameters to efficiently prevent name collisions
1121    let p_form_grant_type = grant_type;
1122    let p_form_client_id = client_id;
1123    let p_form_code = code;
1124    let p_form_redirect_uri = redirect_uri;
1125    let p_form_refresh_token = refresh_token;
1126    let p_form_resource = resource;
1127
1128    let uri_str = format!("{}/oauth2/token", configuration.base_path);
1129    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1130
1131    if let Some(ref user_agent) = configuration.user_agent {
1132        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1133    }
1134    if let Some(ref auth_conf) = configuration.basic_auth {
1135        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
1136    };
1137    if let Some(ref token) = configuration.oauth_access_token {
1138        req_builder = req_builder.bearer_auth(token.to_owned());
1139    };
1140    let mut multipart_form_params = std::collections::HashMap::new();
1141    if let Some(param_value) = p_form_client_id {
1142        multipart_form_params.insert("client_id", param_value.to_string());
1143    }
1144    if let Some(param_value) = p_form_code {
1145        multipart_form_params.insert("code", param_value.to_string());
1146    }
1147    multipart_form_params.insert("grant_type", p_form_grant_type.to_string());
1148    if let Some(param_value) = p_form_redirect_uri {
1149        multipart_form_params.insert("redirect_uri", param_value.to_string());
1150    }
1151    if let Some(param_value) = p_form_refresh_token {
1152        multipart_form_params.insert("refresh_token", param_value.to_string());
1153    }
1154    if let Some(param_value) = p_form_resource {
1155        multipart_form_params.insert("resource", param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
1156    }
1157    req_builder = req_builder.form(&multipart_form_params);
1158
1159    let req = req_builder.build()?;
1160    let resp = configuration.client.execute(req).await?;
1161
1162    let status = resp.status();
1163    let content_type = resp
1164        .headers()
1165        .get("content-type")
1166        .and_then(|v| v.to_str().ok())
1167        .unwrap_or("application/octet-stream");
1168    let content_type = super::ContentType::from(content_type);
1169
1170    if !status.is_client_error() && !status.is_server_error() {
1171        let content = resp.text().await?;
1172        match content_type {
1173            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1174            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2TokenExchange`"))),
1175            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::OAuth2TokenExchange`")))),
1176        }
1177    } else {
1178        let content = resp.text().await?;
1179        let entity: Option<Oauth2TokenExchangeError> = serde_json::from_str(&content).ok();
1180        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1181    }
1182}
1183
1184/// Patch an existing OAuth 2.0 Client using JSON Patch. If you update `client_secret`, the secret will be updated and returned via the API. This is the only time you will be able to retrieve the client secret. Passing a new `client_secret` will clear all rotated secrets.  To perform a seamless client secret rotation, use the `rotateOAuth2ClientSecret` endpoint instead.  OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.
1185pub async fn patch_o_auth2_client(configuration: &configuration::Configuration, id: &str, json_patch: Vec<models::JsonPatch>) -> Result<models::OAuth2Client, Error<PatchOAuth2ClientError>> {
1186    // add a prefix to parameters to efficiently prevent name collisions
1187    let p_path_id = id;
1188    let p_body_json_patch = json_patch;
1189
1190    let uri_str = format!("{}/admin/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1191    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
1192
1193    if let Some(ref user_agent) = configuration.user_agent {
1194        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1195    }
1196    if let Some(ref token) = configuration.bearer_access_token {
1197        req_builder = req_builder.bearer_auth(token.to_owned());
1198    };
1199    req_builder = req_builder.json(&p_body_json_patch);
1200
1201    let req = req_builder.build()?;
1202    let resp = configuration.client.execute(req).await?;
1203
1204    let status = resp.status();
1205    let content_type = resp
1206        .headers()
1207        .get("content-type")
1208        .and_then(|v| v.to_str().ok())
1209        .unwrap_or("application/octet-stream");
1210    let content_type = super::ContentType::from(content_type);
1211
1212    if !status.is_client_error() && !status.is_server_error() {
1213        let content = resp.text().await?;
1214        match content_type {
1215            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1216            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1217            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`")))),
1218        }
1219    } else {
1220        let content = resp.text().await?;
1221        let entity: Option<PatchOAuth2ClientError> = serde_json::from_str(&content).ok();
1222        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1223    }
1224}
1225
1226/// This is the device user verification endpoint. The user is redirected here when trying to log in using the device flow.
1227pub async fn perform_o_auth2_device_verification_flow(configuration: &configuration::Configuration, ) -> Result<models::ErrorOAuth2, Error<PerformOAuth2DeviceVerificationFlowError>> {
1228
1229    let uri_str = format!("{}/oauth2/device/verify", configuration.base_path);
1230    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1231
1232    if let Some(ref user_agent) = configuration.user_agent {
1233        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1234    }
1235
1236    let req = req_builder.build()?;
1237    let resp = configuration.client.execute(req).await?;
1238
1239    let status = resp.status();
1240    let content_type = resp
1241        .headers()
1242        .get("content-type")
1243        .and_then(|v| v.to_str().ok())
1244        .unwrap_or("application/octet-stream");
1245    let content_type = super::ContentType::from(content_type);
1246
1247    if !status.is_client_error() && !status.is_server_error() {
1248        let content = resp.text().await?;
1249        match content_type {
1250            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1251            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ErrorOAuth2`"))),
1252            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::ErrorOAuth2`")))),
1253        }
1254    } else {
1255        let content = resp.text().await?;
1256        let entity: Option<PerformOAuth2DeviceVerificationFlowError> = serde_json::from_str(&content).ok();
1257        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1258    }
1259}
1260
1261/// When an authorization code, hybrid, or implicit OAuth 2.0 Flow is initiated, Ory asks the login provider to authenticate the subject and then tell Ory now about it. If the subject authenticated, he/she must now be asked if the OAuth 2.0 Client which initiated the flow should be allowed to access the resources on the subject's behalf.  The consent challenge is appended to the consent provider's URL to which the subject's user-agent (browser) is redirected to. The consent provider uses that challenge to fetch information on the OAuth2 request and then tells Ory if the subject accepted or rejected the request.  This endpoint tells Ory that the subject has not authorized the OAuth 2.0 client to access resources on his/her behalf. The consent provider must include a reason why the consent was not granted.  The response contains a redirect URL which the consent provider should redirect the user-agent to.  The default consent provider is available via the Ory Managed Account Experience. To customize the consent provider, please head over to the OAuth 2.0 documentation.
1262pub async fn reject_o_auth2_consent_request(configuration: &configuration::Configuration, consent_challenge: &str, reject_o_auth2_request: Option<models::RejectOAuth2Request>) -> Result<models::OAuth2RedirectTo, Error<RejectOAuth2ConsentRequestError>> {
1263    // add a prefix to parameters to efficiently prevent name collisions
1264    let p_query_consent_challenge = consent_challenge;
1265    let p_body_reject_o_auth2_request = reject_o_auth2_request;
1266
1267    let uri_str = format!("{}/admin/oauth2/auth/requests/consent/reject", configuration.base_path);
1268    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1269
1270    req_builder = req_builder.query(&[("consent_challenge", &p_query_consent_challenge.to_string())]);
1271    if let Some(ref user_agent) = configuration.user_agent {
1272        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1273    }
1274    if let Some(ref token) = configuration.bearer_access_token {
1275        req_builder = req_builder.bearer_auth(token.to_owned());
1276    };
1277    req_builder = req_builder.json(&p_body_reject_o_auth2_request);
1278
1279    let req = req_builder.build()?;
1280    let resp = configuration.client.execute(req).await?;
1281
1282    let status = resp.status();
1283    let content_type = resp
1284        .headers()
1285        .get("content-type")
1286        .and_then(|v| v.to_str().ok())
1287        .unwrap_or("application/octet-stream");
1288    let content_type = super::ContentType::from(content_type);
1289
1290    if !status.is_client_error() && !status.is_server_error() {
1291        let content = resp.text().await?;
1292        match content_type {
1293            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1294            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
1295            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::OAuth2RedirectTo`")))),
1296        }
1297    } else {
1298        let content = resp.text().await?;
1299        let entity: Option<RejectOAuth2ConsentRequestError> = serde_json::from_str(&content).ok();
1300        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1301    }
1302}
1303
1304/// When an authorization code, hybrid, or implicit OAuth 2.0 Flow is initiated, Ory asks the login provider to authenticate the subject and then tell the Ory OAuth2 Service about it.  The authentication challenge is appended to the login provider URL to which the subject's user-agent (browser) is redirected to. The login provider uses that challenge to fetch information on the OAuth2 request and then accept or reject the requested authentication process.  This endpoint tells Ory that the subject has not authenticated and includes a reason why the authentication was denied.  The response contains a redirect URL which the login provider should redirect the user-agent to.
1305pub async fn reject_o_auth2_login_request(configuration: &configuration::Configuration, login_challenge: &str, reject_o_auth2_request: Option<models::RejectOAuth2Request>) -> Result<models::OAuth2RedirectTo, Error<RejectOAuth2LoginRequestError>> {
1306    // add a prefix to parameters to efficiently prevent name collisions
1307    let p_query_login_challenge = login_challenge;
1308    let p_body_reject_o_auth2_request = reject_o_auth2_request;
1309
1310    let uri_str = format!("{}/admin/oauth2/auth/requests/login/reject", configuration.base_path);
1311    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1312
1313    req_builder = req_builder.query(&[("login_challenge", &p_query_login_challenge.to_string())]);
1314    if let Some(ref user_agent) = configuration.user_agent {
1315        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1316    }
1317    if let Some(ref token) = configuration.bearer_access_token {
1318        req_builder = req_builder.bearer_auth(token.to_owned());
1319    };
1320    req_builder = req_builder.json(&p_body_reject_o_auth2_request);
1321
1322    let req = req_builder.build()?;
1323    let resp = configuration.client.execute(req).await?;
1324
1325    let status = resp.status();
1326    let content_type = resp
1327        .headers()
1328        .get("content-type")
1329        .and_then(|v| v.to_str().ok())
1330        .unwrap_or("application/octet-stream");
1331    let content_type = super::ContentType::from(content_type);
1332
1333    if !status.is_client_error() && !status.is_server_error() {
1334        let content = resp.text().await?;
1335        match content_type {
1336            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1337            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
1338            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::OAuth2RedirectTo`")))),
1339        }
1340    } else {
1341        let content = resp.text().await?;
1342        let entity: Option<RejectOAuth2LoginRequestError> = serde_json::from_str(&content).ok();
1343        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1344    }
1345}
1346
1347/// When a user or an application requests Ory OAuth 2.0 to remove the session state of a subject, this endpoint is used to deny that logout request. No HTTP request body is required.  The response is empty as the logout provider has to chose what action to perform next.
1348pub async fn reject_o_auth2_logout_request(configuration: &configuration::Configuration, logout_challenge: &str) -> Result<(), Error<RejectOAuth2LogoutRequestError>> {
1349    // add a prefix to parameters to efficiently prevent name collisions
1350    let p_query_logout_challenge = logout_challenge;
1351
1352    let uri_str = format!("{}/admin/oauth2/auth/requests/logout/reject", configuration.base_path);
1353    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1354
1355    req_builder = req_builder.query(&[("logout_challenge", &p_query_logout_challenge.to_string())]);
1356    if let Some(ref user_agent) = configuration.user_agent {
1357        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1358    }
1359    if let Some(ref token) = configuration.bearer_access_token {
1360        req_builder = req_builder.bearer_auth(token.to_owned());
1361    };
1362
1363    let req = req_builder.build()?;
1364    let resp = configuration.client.execute(req).await?;
1365
1366    let status = resp.status();
1367
1368    if !status.is_client_error() && !status.is_server_error() {
1369        Ok(())
1370    } else {
1371        let content = resp.text().await?;
1372        let entity: Option<RejectOAuth2LogoutRequestError> = serde_json::from_str(&content).ok();
1373        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1374    }
1375}
1376
1377/// This endpoint revokes a subject's granted consent sessions and invalidates all associated OAuth 2.0 Access Tokens. You may also only revoke sessions for a specific OAuth 2.0 Client ID.
1378pub async fn revoke_o_auth2_consent_sessions(configuration: &configuration::Configuration, subject: Option<&str>, client: Option<&str>, consent_request_id: Option<&str>, all: Option<bool>) -> Result<(), Error<RevokeOAuth2ConsentSessionsError>> {
1379    // add a prefix to parameters to efficiently prevent name collisions
1380    let p_query_subject = subject;
1381    let p_query_client = client;
1382    let p_query_consent_request_id = consent_request_id;
1383    let p_query_all = all;
1384
1385    let uri_str = format!("{}/admin/oauth2/auth/sessions/consent", configuration.base_path);
1386    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
1387
1388    if let Some(ref param_value) = p_query_subject {
1389        req_builder = req_builder.query(&[("subject", &param_value.to_string())]);
1390    }
1391    if let Some(ref param_value) = p_query_client {
1392        req_builder = req_builder.query(&[("client", &param_value.to_string())]);
1393    }
1394    if let Some(ref param_value) = p_query_consent_request_id {
1395        req_builder = req_builder.query(&[("consent_request_id", &param_value.to_string())]);
1396    }
1397    if let Some(ref param_value) = p_query_all {
1398        req_builder = req_builder.query(&[("all", &param_value.to_string())]);
1399    }
1400    if let Some(ref user_agent) = configuration.user_agent {
1401        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1402    }
1403    if let Some(ref token) = configuration.bearer_access_token {
1404        req_builder = req_builder.bearer_auth(token.to_owned());
1405    };
1406
1407    let req = req_builder.build()?;
1408    let resp = configuration.client.execute(req).await?;
1409
1410    let status = resp.status();
1411
1412    if !status.is_client_error() && !status.is_server_error() {
1413        Ok(())
1414    } else {
1415        let content = resp.text().await?;
1416        let entity: Option<RevokeOAuth2ConsentSessionsError> = serde_json::from_str(&content).ok();
1417        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1418    }
1419}
1420
1421/// This endpoint invalidates authentication sessions. After revoking the authentication session(s), the subject has to re-authenticate at the Ory OAuth2 Provider. This endpoint does not invalidate any tokens.  If you send the subject in a query param, all authentication sessions that belong to that subject are revoked. No OpenID Connect Front- or Back-channel logout is performed in this case.  Alternatively, you can send a SessionID via `sid` query param, in which case, only the session that is connected to that SessionID is revoked. OpenID Connect Back-channel logout is performed in this case.  When using Ory for the identity provider, the login provider will also invalidate the session cookie.
1422pub async fn revoke_o_auth2_login_sessions(configuration: &configuration::Configuration, subject: Option<&str>, sid: Option<&str>) -> Result<(), Error<RevokeOAuth2LoginSessionsError>> {
1423    // add a prefix to parameters to efficiently prevent name collisions
1424    let p_query_subject = subject;
1425    let p_query_sid = sid;
1426
1427    let uri_str = format!("{}/admin/oauth2/auth/sessions/login", configuration.base_path);
1428    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
1429
1430    if let Some(ref param_value) = p_query_subject {
1431        req_builder = req_builder.query(&[("subject", &param_value.to_string())]);
1432    }
1433    if let Some(ref param_value) = p_query_sid {
1434        req_builder = req_builder.query(&[("sid", &param_value.to_string())]);
1435    }
1436    if let Some(ref user_agent) = configuration.user_agent {
1437        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1438    }
1439    if let Some(ref token) = configuration.bearer_access_token {
1440        req_builder = req_builder.bearer_auth(token.to_owned());
1441    };
1442
1443    let req = req_builder.build()?;
1444    let resp = configuration.client.execute(req).await?;
1445
1446    let status = resp.status();
1447
1448    if !status.is_client_error() && !status.is_server_error() {
1449        Ok(())
1450    } else {
1451        let content = resp.text().await?;
1452        let entity: Option<RevokeOAuth2LoginSessionsError> = serde_json::from_str(&content).ok();
1453        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1454    }
1455}
1456
1457/// Revoking a token (both access and refresh) means that the tokens will be invalid. A revoked access token can no longer be used to make access requests, and a revoked refresh token can no longer be used to refresh an access token. Revoking a refresh token also invalidates the access token that was created with it. A token may only be revoked by the client the token was generated for.
1458pub async fn revoke_o_auth2_token(configuration: &configuration::Configuration, token: &str, client_id: Option<&str>, client_secret: Option<&str>) -> Result<(), Error<RevokeOAuth2TokenError>> {
1459    // add a prefix to parameters to efficiently prevent name collisions
1460    let p_form_token = token;
1461    let p_form_client_id = client_id;
1462    let p_form_client_secret = client_secret;
1463
1464    let uri_str = format!("{}/oauth2/revoke", configuration.base_path);
1465    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1466
1467    if let Some(ref user_agent) = configuration.user_agent {
1468        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1469    }
1470    if let Some(ref auth_conf) = configuration.basic_auth {
1471        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
1472    };
1473    if let Some(ref token) = configuration.oauth_access_token {
1474        req_builder = req_builder.bearer_auth(token.to_owned());
1475    };
1476    let mut multipart_form_params = std::collections::HashMap::new();
1477    if let Some(param_value) = p_form_client_id {
1478        multipart_form_params.insert("client_id", param_value.to_string());
1479    }
1480    if let Some(param_value) = p_form_client_secret {
1481        multipart_form_params.insert("client_secret", param_value.to_string());
1482    }
1483    multipart_form_params.insert("token", p_form_token.to_string());
1484    req_builder = req_builder.form(&multipart_form_params);
1485
1486    let req = req_builder.build()?;
1487    let resp = configuration.client.execute(req).await?;
1488
1489    let status = resp.status();
1490
1491    if !status.is_client_error() && !status.is_server_error() {
1492        Ok(())
1493    } else {
1494        let content = resp.text().await?;
1495        let entity: Option<RevokeOAuth2TokenError> = serde_json::from_str(&content).ok();
1496        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1497    }
1498}
1499
1500/// Rotates an OAuth 2.0 client's secrets. The old secret will remain valid for authentication, allowing for zero-downtime secret rotations. A new secret will be generated and returned in the response.  Up to five rotated secrets are retained. Use the `deleteRotatedOAuth2ClientSecrets` endpoint to remove old rotated secrets when they are no longer needed.  Supply `client_secret` in the request body to rotate to a specific value instead of a generated one. The request body is optional.
1501pub async fn rotate_o_auth2_client_secret(configuration: &configuration::Configuration, id: &str, rotate_o_auth2_client_secret_body: Option<models::RotateOAuth2ClientSecretBody>) -> Result<models::OAuth2Client, Error<RotateOAuth2ClientSecretError>> {
1502    // add a prefix to parameters to efficiently prevent name collisions
1503    let p_path_id = id;
1504    let p_body_rotate_o_auth2_client_secret_body = rotate_o_auth2_client_secret_body;
1505
1506    let uri_str = format!("{}/admin/clients/{id}/secrets/rotate", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1507    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1508
1509    if let Some(ref user_agent) = configuration.user_agent {
1510        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1511    }
1512    if let Some(ref token) = configuration.bearer_access_token {
1513        req_builder = req_builder.bearer_auth(token.to_owned());
1514    };
1515    req_builder = req_builder.json(&p_body_rotate_o_auth2_client_secret_body);
1516
1517    let req = req_builder.build()?;
1518    let resp = configuration.client.execute(req).await?;
1519
1520    let status = resp.status();
1521    let content_type = resp
1522        .headers()
1523        .get("content-type")
1524        .and_then(|v| v.to_str().ok())
1525        .unwrap_or("application/octet-stream");
1526    let content_type = super::ContentType::from(content_type);
1527
1528    if !status.is_client_error() && !status.is_server_error() {
1529        let content = resp.text().await?;
1530        match content_type {
1531            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1532            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1533            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`")))),
1534        }
1535    } else {
1536        let content = resp.text().await?;
1537        let entity: Option<RotateOAuth2ClientSecretError> = serde_json::from_str(&content).ok();
1538        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1539    }
1540}
1541
1542/// Replaces an existing OAuth 2.0 Client with the payload you send. If you pass `client_secret` the secret is used, otherwise the existing secret is used. Rotated secrets will be cleared if you pass a new `client_secret`.  If set, the secret is echoed in the response. It is not possible to retrieve it later on.  To perform a seamless client secret rotation, use the `rotateOAuth2ClientSecret` endpoint instead.  OAuth 2.0 Clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.
1543pub async fn set_o_auth2_client(configuration: &configuration::Configuration, id: &str, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<SetOAuth2ClientError>> {
1544    // add a prefix to parameters to efficiently prevent name collisions
1545    let p_path_id = id;
1546    let p_body_o_auth2_client = o_auth2_client;
1547
1548    let uri_str = format!("{}/admin/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1549    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1550
1551    if let Some(ref user_agent) = configuration.user_agent {
1552        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1553    }
1554    if let Some(ref token) = configuration.bearer_access_token {
1555        req_builder = req_builder.bearer_auth(token.to_owned());
1556    };
1557    req_builder = req_builder.json(&p_body_o_auth2_client);
1558
1559    let req = req_builder.build()?;
1560    let resp = configuration.client.execute(req).await?;
1561
1562    let status = resp.status();
1563    let content_type = resp
1564        .headers()
1565        .get("content-type")
1566        .and_then(|v| v.to_str().ok())
1567        .unwrap_or("application/octet-stream");
1568    let content_type = super::ContentType::from(content_type);
1569
1570    if !status.is_client_error() && !status.is_server_error() {
1571        let content = resp.text().await?;
1572        match content_type {
1573            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1574            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1575            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`")))),
1576        }
1577    } else {
1578        let content = resp.text().await?;
1579        let entity: Option<SetOAuth2ClientError> = serde_json::from_str(&content).ok();
1580        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1581    }
1582}
1583
1584/// Set lifespans of different token types issued for this OAuth 2.0 client. Does not modify other fields.
1585pub async fn set_o_auth2_client_lifespans(configuration: &configuration::Configuration, id: &str, o_auth2_client_token_lifespans: Option<models::OAuth2ClientTokenLifespans>) -> Result<models::OAuth2Client, Error<SetOAuth2ClientLifespansError>> {
1586    // add a prefix to parameters to efficiently prevent name collisions
1587    let p_path_id = id;
1588    let p_body_o_auth2_client_token_lifespans = o_auth2_client_token_lifespans;
1589
1590    let uri_str = format!("{}/admin/clients/{id}/lifespans", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1591    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1592
1593    if let Some(ref user_agent) = configuration.user_agent {
1594        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1595    }
1596    if let Some(ref token) = configuration.bearer_access_token {
1597        req_builder = req_builder.bearer_auth(token.to_owned());
1598    };
1599    req_builder = req_builder.json(&p_body_o_auth2_client_token_lifespans);
1600
1601    let req = req_builder.build()?;
1602    let resp = configuration.client.execute(req).await?;
1603
1604    let status = resp.status();
1605    let content_type = resp
1606        .headers()
1607        .get("content-type")
1608        .and_then(|v| v.to_str().ok())
1609        .unwrap_or("application/octet-stream");
1610    let content_type = super::ContentType::from(content_type);
1611
1612    if !status.is_client_error() && !status.is_server_error() {
1613        let content = resp.text().await?;
1614        match content_type {
1615            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1616            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1617            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`")))),
1618        }
1619    } else {
1620        let content = resp.text().await?;
1621        let entity: Option<SetOAuth2ClientLifespansError> = serde_json::from_str(&content).ok();
1622        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1623    }
1624}
1625
1626/// Use this endpoint to establish a trust relationship for a JWT issuer to perform JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants [RFC7523](https://datatracker.ietf.org/doc/html/rfc7523).
1627pub async fn trust_o_auth2_jwt_grant_issuer(configuration: &configuration::Configuration, trust_o_auth2_jwt_grant_issuer: Option<models::TrustOAuth2JwtGrantIssuer>) -> Result<models::TrustedOAuth2JwtGrantIssuer, Error<TrustOAuth2JwtGrantIssuerError>> {
1628    // add a prefix to parameters to efficiently prevent name collisions
1629    let p_body_trust_o_auth2_jwt_grant_issuer = trust_o_auth2_jwt_grant_issuer;
1630
1631    let uri_str = format!("{}/admin/trust/grants/jwt-bearer/issuers", configuration.base_path);
1632    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1633
1634    if let Some(ref user_agent) = configuration.user_agent {
1635        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1636    }
1637    if let Some(ref token) = configuration.bearer_access_token {
1638        req_builder = req_builder.bearer_auth(token.to_owned());
1639    };
1640    req_builder = req_builder.json(&p_body_trust_o_auth2_jwt_grant_issuer);
1641
1642    let req = req_builder.build()?;
1643    let resp = configuration.client.execute(req).await?;
1644
1645    let status = resp.status();
1646    let content_type = resp
1647        .headers()
1648        .get("content-type")
1649        .and_then(|v| v.to_str().ok())
1650        .unwrap_or("application/octet-stream");
1651    let content_type = super::ContentType::from(content_type);
1652
1653    if !status.is_client_error() && !status.is_server_error() {
1654        let content = resp.text().await?;
1655        match content_type {
1656            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1657            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrustedOAuth2JwtGrantIssuer`"))),
1658            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::TrustedOAuth2JwtGrantIssuer`")))),
1659        }
1660    } else {
1661        let content = resp.text().await?;
1662        let entity: Option<TrustOAuth2JwtGrantIssuerError> = serde_json::from_str(&content).ok();
1663        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1664    }
1665}
1666