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.80
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, ) -> Result<models::ErrorOAuth2, Error<OAuth2AuthorizeError>> {
1042
1043    let uri_str = format!("{}/oauth2/auth", configuration.base_path);
1044    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1045
1046    if let Some(ref user_agent) = configuration.user_agent {
1047        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1048    }
1049
1050    let req = req_builder.build()?;
1051    let resp = configuration.client.execute(req).await?;
1052
1053    let status = resp.status();
1054    let content_type = resp
1055        .headers()
1056        .get("content-type")
1057        .and_then(|v| v.to_str().ok())
1058        .unwrap_or("application/octet-stream");
1059    let content_type = super::ContentType::from(content_type);
1060
1061    if !status.is_client_error() && !status.is_server_error() {
1062        let content = resp.text().await?;
1063        match content_type {
1064            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1065            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ErrorOAuth2`"))),
1066            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`")))),
1067        }
1068    } else {
1069        let content = resp.text().await?;
1070        let entity: Option<OAuth2AuthorizeError> = serde_json::from_str(&content).ok();
1071        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1072    }
1073}
1074
1075/// 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
1076pub async fn o_auth2_device_flow(configuration: &configuration::Configuration, ) -> Result<models::DeviceAuthorization, Error<OAuth2DeviceFlowError>> {
1077
1078    let uri_str = format!("{}/oauth2/device/auth", configuration.base_path);
1079    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1080
1081    if let Some(ref user_agent) = configuration.user_agent {
1082        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1083    }
1084
1085    let req = req_builder.build()?;
1086    let resp = configuration.client.execute(req).await?;
1087
1088    let status = resp.status();
1089    let content_type = resp
1090        .headers()
1091        .get("content-type")
1092        .and_then(|v| v.to_str().ok())
1093        .unwrap_or("application/octet-stream");
1094    let content_type = super::ContentType::from(content_type);
1095
1096    if !status.is_client_error() && !status.is_server_error() {
1097        let content = resp.text().await?;
1098        match content_type {
1099            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1100            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeviceAuthorization`"))),
1101            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`")))),
1102        }
1103    } else {
1104        let content = resp.text().await?;
1105        let entity: Option<OAuth2DeviceFlowError> = serde_json::from_str(&content).ok();
1106        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1107    }
1108}
1109
1110/// 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.
1111pub 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>) -> Result<models::OAuth2TokenExchange, Error<Oauth2TokenExchangeError>> {
1112    // add a prefix to parameters to efficiently prevent name collisions
1113    let p_form_grant_type = grant_type;
1114    let p_form_client_id = client_id;
1115    let p_form_code = code;
1116    let p_form_redirect_uri = redirect_uri;
1117    let p_form_refresh_token = refresh_token;
1118
1119    let uri_str = format!("{}/oauth2/token", configuration.base_path);
1120    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1121
1122    if let Some(ref user_agent) = configuration.user_agent {
1123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1124    }
1125    if let Some(ref auth_conf) = configuration.basic_auth {
1126        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
1127    };
1128    if let Some(ref token) = configuration.oauth_access_token {
1129        req_builder = req_builder.bearer_auth(token.to_owned());
1130    };
1131    let mut multipart_form_params = std::collections::HashMap::new();
1132    if let Some(param_value) = p_form_client_id {
1133        multipart_form_params.insert("client_id", param_value.to_string());
1134    }
1135    if let Some(param_value) = p_form_code {
1136        multipart_form_params.insert("code", param_value.to_string());
1137    }
1138    multipart_form_params.insert("grant_type", p_form_grant_type.to_string());
1139    if let Some(param_value) = p_form_redirect_uri {
1140        multipart_form_params.insert("redirect_uri", param_value.to_string());
1141    }
1142    if let Some(param_value) = p_form_refresh_token {
1143        multipart_form_params.insert("refresh_token", param_value.to_string());
1144    }
1145    req_builder = req_builder.form(&multipart_form_params);
1146
1147    let req = req_builder.build()?;
1148    let resp = configuration.client.execute(req).await?;
1149
1150    let status = resp.status();
1151    let content_type = resp
1152        .headers()
1153        .get("content-type")
1154        .and_then(|v| v.to_str().ok())
1155        .unwrap_or("application/octet-stream");
1156    let content_type = super::ContentType::from(content_type);
1157
1158    if !status.is_client_error() && !status.is_server_error() {
1159        let content = resp.text().await?;
1160        match content_type {
1161            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1162            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2TokenExchange`"))),
1163            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`")))),
1164        }
1165    } else {
1166        let content = resp.text().await?;
1167        let entity: Option<Oauth2TokenExchangeError> = serde_json::from_str(&content).ok();
1168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1169    }
1170}
1171
1172/// 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.
1173pub async fn patch_o_auth2_client(configuration: &configuration::Configuration, id: &str, json_patch: Vec<models::JsonPatch>) -> Result<models::OAuth2Client, Error<PatchOAuth2ClientError>> {
1174    // add a prefix to parameters to efficiently prevent name collisions
1175    let p_path_id = id;
1176    let p_body_json_patch = json_patch;
1177
1178    let uri_str = format!("{}/admin/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1179    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
1180
1181    if let Some(ref user_agent) = configuration.user_agent {
1182        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1183    }
1184    if let Some(ref token) = configuration.bearer_access_token {
1185        req_builder = req_builder.bearer_auth(token.to_owned());
1186    };
1187    req_builder = req_builder.json(&p_body_json_patch);
1188
1189    let req = req_builder.build()?;
1190    let resp = configuration.client.execute(req).await?;
1191
1192    let status = resp.status();
1193    let content_type = resp
1194        .headers()
1195        .get("content-type")
1196        .and_then(|v| v.to_str().ok())
1197        .unwrap_or("application/octet-stream");
1198    let content_type = super::ContentType::from(content_type);
1199
1200    if !status.is_client_error() && !status.is_server_error() {
1201        let content = resp.text().await?;
1202        match content_type {
1203            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1204            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1205            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`")))),
1206        }
1207    } else {
1208        let content = resp.text().await?;
1209        let entity: Option<PatchOAuth2ClientError> = serde_json::from_str(&content).ok();
1210        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1211    }
1212}
1213
1214/// This is the device user verification endpoint. The user is redirected here when trying to log in using the device flow.
1215pub async fn perform_o_auth2_device_verification_flow(configuration: &configuration::Configuration, ) -> Result<models::ErrorOAuth2, Error<PerformOAuth2DeviceVerificationFlowError>> {
1216
1217    let uri_str = format!("{}/oauth2/device/verify", configuration.base_path);
1218    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1219
1220    if let Some(ref user_agent) = configuration.user_agent {
1221        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1222    }
1223
1224    let req = req_builder.build()?;
1225    let resp = configuration.client.execute(req).await?;
1226
1227    let status = resp.status();
1228    let content_type = resp
1229        .headers()
1230        .get("content-type")
1231        .and_then(|v| v.to_str().ok())
1232        .unwrap_or("application/octet-stream");
1233    let content_type = super::ContentType::from(content_type);
1234
1235    if !status.is_client_error() && !status.is_server_error() {
1236        let content = resp.text().await?;
1237        match content_type {
1238            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1239            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ErrorOAuth2`"))),
1240            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`")))),
1241        }
1242    } else {
1243        let content = resp.text().await?;
1244        let entity: Option<PerformOAuth2DeviceVerificationFlowError> = serde_json::from_str(&content).ok();
1245        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1246    }
1247}
1248
1249/// 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.
1250pub 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>> {
1251    // add a prefix to parameters to efficiently prevent name collisions
1252    let p_query_consent_challenge = consent_challenge;
1253    let p_body_reject_o_auth2_request = reject_o_auth2_request;
1254
1255    let uri_str = format!("{}/admin/oauth2/auth/requests/consent/reject", configuration.base_path);
1256    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1257
1258    req_builder = req_builder.query(&[("consent_challenge", &p_query_consent_challenge.to_string())]);
1259    if let Some(ref user_agent) = configuration.user_agent {
1260        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1261    }
1262    if let Some(ref token) = configuration.bearer_access_token {
1263        req_builder = req_builder.bearer_auth(token.to_owned());
1264    };
1265    req_builder = req_builder.json(&p_body_reject_o_auth2_request);
1266
1267    let req = req_builder.build()?;
1268    let resp = configuration.client.execute(req).await?;
1269
1270    let status = resp.status();
1271    let content_type = resp
1272        .headers()
1273        .get("content-type")
1274        .and_then(|v| v.to_str().ok())
1275        .unwrap_or("application/octet-stream");
1276    let content_type = super::ContentType::from(content_type);
1277
1278    if !status.is_client_error() && !status.is_server_error() {
1279        let content = resp.text().await?;
1280        match content_type {
1281            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1282            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
1283            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`")))),
1284        }
1285    } else {
1286        let content = resp.text().await?;
1287        let entity: Option<RejectOAuth2ConsentRequestError> = serde_json::from_str(&content).ok();
1288        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1289    }
1290}
1291
1292/// 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.
1293pub 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>> {
1294    // add a prefix to parameters to efficiently prevent name collisions
1295    let p_query_login_challenge = login_challenge;
1296    let p_body_reject_o_auth2_request = reject_o_auth2_request;
1297
1298    let uri_str = format!("{}/admin/oauth2/auth/requests/login/reject", configuration.base_path);
1299    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1300
1301    req_builder = req_builder.query(&[("login_challenge", &p_query_login_challenge.to_string())]);
1302    if let Some(ref user_agent) = configuration.user_agent {
1303        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1304    }
1305    if let Some(ref token) = configuration.bearer_access_token {
1306        req_builder = req_builder.bearer_auth(token.to_owned());
1307    };
1308    req_builder = req_builder.json(&p_body_reject_o_auth2_request);
1309
1310    let req = req_builder.build()?;
1311    let resp = configuration.client.execute(req).await?;
1312
1313    let status = resp.status();
1314    let content_type = resp
1315        .headers()
1316        .get("content-type")
1317        .and_then(|v| v.to_str().ok())
1318        .unwrap_or("application/octet-stream");
1319    let content_type = super::ContentType::from(content_type);
1320
1321    if !status.is_client_error() && !status.is_server_error() {
1322        let content = resp.text().await?;
1323        match content_type {
1324            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1325            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2RedirectTo`"))),
1326            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`")))),
1327        }
1328    } else {
1329        let content = resp.text().await?;
1330        let entity: Option<RejectOAuth2LoginRequestError> = serde_json::from_str(&content).ok();
1331        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1332    }
1333}
1334
1335/// 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.
1336pub async fn reject_o_auth2_logout_request(configuration: &configuration::Configuration, logout_challenge: &str) -> Result<(), Error<RejectOAuth2LogoutRequestError>> {
1337    // add a prefix to parameters to efficiently prevent name collisions
1338    let p_query_logout_challenge = logout_challenge;
1339
1340    let uri_str = format!("{}/admin/oauth2/auth/requests/logout/reject", configuration.base_path);
1341    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1342
1343    req_builder = req_builder.query(&[("logout_challenge", &p_query_logout_challenge.to_string())]);
1344    if let Some(ref user_agent) = configuration.user_agent {
1345        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1346    }
1347    if let Some(ref token) = configuration.bearer_access_token {
1348        req_builder = req_builder.bearer_auth(token.to_owned());
1349    };
1350
1351    let req = req_builder.build()?;
1352    let resp = configuration.client.execute(req).await?;
1353
1354    let status = resp.status();
1355
1356    if !status.is_client_error() && !status.is_server_error() {
1357        Ok(())
1358    } else {
1359        let content = resp.text().await?;
1360        let entity: Option<RejectOAuth2LogoutRequestError> = serde_json::from_str(&content).ok();
1361        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1362    }
1363}
1364
1365/// 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.
1366pub 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>> {
1367    // add a prefix to parameters to efficiently prevent name collisions
1368    let p_query_subject = subject;
1369    let p_query_client = client;
1370    let p_query_consent_request_id = consent_request_id;
1371    let p_query_all = all;
1372
1373    let uri_str = format!("{}/admin/oauth2/auth/sessions/consent", configuration.base_path);
1374    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
1375
1376    if let Some(ref param_value) = p_query_subject {
1377        req_builder = req_builder.query(&[("subject", &param_value.to_string())]);
1378    }
1379    if let Some(ref param_value) = p_query_client {
1380        req_builder = req_builder.query(&[("client", &param_value.to_string())]);
1381    }
1382    if let Some(ref param_value) = p_query_consent_request_id {
1383        req_builder = req_builder.query(&[("consent_request_id", &param_value.to_string())]);
1384    }
1385    if let Some(ref param_value) = p_query_all {
1386        req_builder = req_builder.query(&[("all", &param_value.to_string())]);
1387    }
1388    if let Some(ref user_agent) = configuration.user_agent {
1389        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1390    }
1391    if let Some(ref token) = configuration.bearer_access_token {
1392        req_builder = req_builder.bearer_auth(token.to_owned());
1393    };
1394
1395    let req = req_builder.build()?;
1396    let resp = configuration.client.execute(req).await?;
1397
1398    let status = resp.status();
1399
1400    if !status.is_client_error() && !status.is_server_error() {
1401        Ok(())
1402    } else {
1403        let content = resp.text().await?;
1404        let entity: Option<RevokeOAuth2ConsentSessionsError> = serde_json::from_str(&content).ok();
1405        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1406    }
1407}
1408
1409/// 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.
1410pub async fn revoke_o_auth2_login_sessions(configuration: &configuration::Configuration, subject: Option<&str>, sid: Option<&str>) -> Result<(), Error<RevokeOAuth2LoginSessionsError>> {
1411    // add a prefix to parameters to efficiently prevent name collisions
1412    let p_query_subject = subject;
1413    let p_query_sid = sid;
1414
1415    let uri_str = format!("{}/admin/oauth2/auth/sessions/login", configuration.base_path);
1416    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
1417
1418    if let Some(ref param_value) = p_query_subject {
1419        req_builder = req_builder.query(&[("subject", &param_value.to_string())]);
1420    }
1421    if let Some(ref param_value) = p_query_sid {
1422        req_builder = req_builder.query(&[("sid", &param_value.to_string())]);
1423    }
1424    if let Some(ref user_agent) = configuration.user_agent {
1425        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1426    }
1427    if let Some(ref token) = configuration.bearer_access_token {
1428        req_builder = req_builder.bearer_auth(token.to_owned());
1429    };
1430
1431    let req = req_builder.build()?;
1432    let resp = configuration.client.execute(req).await?;
1433
1434    let status = resp.status();
1435
1436    if !status.is_client_error() && !status.is_server_error() {
1437        Ok(())
1438    } else {
1439        let content = resp.text().await?;
1440        let entity: Option<RevokeOAuth2LoginSessionsError> = serde_json::from_str(&content).ok();
1441        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1442    }
1443}
1444
1445/// 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.
1446pub async fn revoke_o_auth2_token(configuration: &configuration::Configuration, token: &str, client_id: Option<&str>, client_secret: Option<&str>) -> Result<(), Error<RevokeOAuth2TokenError>> {
1447    // add a prefix to parameters to efficiently prevent name collisions
1448    let p_form_token = token;
1449    let p_form_client_id = client_id;
1450    let p_form_client_secret = client_secret;
1451
1452    let uri_str = format!("{}/oauth2/revoke", configuration.base_path);
1453    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1454
1455    if let Some(ref user_agent) = configuration.user_agent {
1456        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1457    }
1458    if let Some(ref auth_conf) = configuration.basic_auth {
1459        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
1460    };
1461    if let Some(ref token) = configuration.oauth_access_token {
1462        req_builder = req_builder.bearer_auth(token.to_owned());
1463    };
1464    let mut multipart_form_params = std::collections::HashMap::new();
1465    if let Some(param_value) = p_form_client_id {
1466        multipart_form_params.insert("client_id", param_value.to_string());
1467    }
1468    if let Some(param_value) = p_form_client_secret {
1469        multipart_form_params.insert("client_secret", param_value.to_string());
1470    }
1471    multipart_form_params.insert("token", p_form_token.to_string());
1472    req_builder = req_builder.form(&multipart_form_params);
1473
1474    let req = req_builder.build()?;
1475    let resp = configuration.client.execute(req).await?;
1476
1477    let status = resp.status();
1478
1479    if !status.is_client_error() && !status.is_server_error() {
1480        Ok(())
1481    } else {
1482        let content = resp.text().await?;
1483        let entity: Option<RevokeOAuth2TokenError> = serde_json::from_str(&content).ok();
1484        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1485    }
1486}
1487
1488/// 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.
1489pub 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>> {
1490    // add a prefix to parameters to efficiently prevent name collisions
1491    let p_path_id = id;
1492    let p_body_rotate_o_auth2_client_secret_body = rotate_o_auth2_client_secret_body;
1493
1494    let uri_str = format!("{}/admin/clients/{id}/secrets/rotate", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1495    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1496
1497    if let Some(ref user_agent) = configuration.user_agent {
1498        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1499    }
1500    if let Some(ref token) = configuration.bearer_access_token {
1501        req_builder = req_builder.bearer_auth(token.to_owned());
1502    };
1503    req_builder = req_builder.json(&p_body_rotate_o_auth2_client_secret_body);
1504
1505    let req = req_builder.build()?;
1506    let resp = configuration.client.execute(req).await?;
1507
1508    let status = resp.status();
1509    let content_type = resp
1510        .headers()
1511        .get("content-type")
1512        .and_then(|v| v.to_str().ok())
1513        .unwrap_or("application/octet-stream");
1514    let content_type = super::ContentType::from(content_type);
1515
1516    if !status.is_client_error() && !status.is_server_error() {
1517        let content = resp.text().await?;
1518        match content_type {
1519            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1520            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1521            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`")))),
1522        }
1523    } else {
1524        let content = resp.text().await?;
1525        let entity: Option<RotateOAuth2ClientSecretError> = serde_json::from_str(&content).ok();
1526        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1527    }
1528}
1529
1530/// 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.
1531pub async fn set_o_auth2_client(configuration: &configuration::Configuration, id: &str, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<SetOAuth2ClientError>> {
1532    // add a prefix to parameters to efficiently prevent name collisions
1533    let p_path_id = id;
1534    let p_body_o_auth2_client = o_auth2_client;
1535
1536    let uri_str = format!("{}/admin/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1537    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1538
1539    if let Some(ref user_agent) = configuration.user_agent {
1540        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1541    }
1542    if let Some(ref token) = configuration.bearer_access_token {
1543        req_builder = req_builder.bearer_auth(token.to_owned());
1544    };
1545    req_builder = req_builder.json(&p_body_o_auth2_client);
1546
1547    let req = req_builder.build()?;
1548    let resp = configuration.client.execute(req).await?;
1549
1550    let status = resp.status();
1551    let content_type = resp
1552        .headers()
1553        .get("content-type")
1554        .and_then(|v| v.to_str().ok())
1555        .unwrap_or("application/octet-stream");
1556    let content_type = super::ContentType::from(content_type);
1557
1558    if !status.is_client_error() && !status.is_server_error() {
1559        let content = resp.text().await?;
1560        match content_type {
1561            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1562            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1563            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`")))),
1564        }
1565    } else {
1566        let content = resp.text().await?;
1567        let entity: Option<SetOAuth2ClientError> = serde_json::from_str(&content).ok();
1568        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1569    }
1570}
1571
1572/// Set lifespans of different token types issued for this OAuth 2.0 client. Does not modify other fields.
1573pub 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>> {
1574    // add a prefix to parameters to efficiently prevent name collisions
1575    let p_path_id = id;
1576    let p_body_o_auth2_client_token_lifespans = o_auth2_client_token_lifespans;
1577
1578    let uri_str = format!("{}/admin/clients/{id}/lifespans", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1579    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1580
1581    if let Some(ref user_agent) = configuration.user_agent {
1582        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1583    }
1584    if let Some(ref token) = configuration.bearer_access_token {
1585        req_builder = req_builder.bearer_auth(token.to_owned());
1586    };
1587    req_builder = req_builder.json(&p_body_o_auth2_client_token_lifespans);
1588
1589    let req = req_builder.build()?;
1590    let resp = configuration.client.execute(req).await?;
1591
1592    let status = resp.status();
1593    let content_type = resp
1594        .headers()
1595        .get("content-type")
1596        .and_then(|v| v.to_str().ok())
1597        .unwrap_or("application/octet-stream");
1598    let content_type = super::ContentType::from(content_type);
1599
1600    if !status.is_client_error() && !status.is_server_error() {
1601        let content = resp.text().await?;
1602        match content_type {
1603            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1604            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
1605            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`")))),
1606        }
1607    } else {
1608        let content = resp.text().await?;
1609        let entity: Option<SetOAuth2ClientLifespansError> = serde_json::from_str(&content).ok();
1610        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1611    }
1612}
1613
1614/// 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).
1615pub 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>> {
1616    // add a prefix to parameters to efficiently prevent name collisions
1617    let p_body_trust_o_auth2_jwt_grant_issuer = trust_o_auth2_jwt_grant_issuer;
1618
1619    let uri_str = format!("{}/admin/trust/grants/jwt-bearer/issuers", configuration.base_path);
1620    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1621
1622    if let Some(ref user_agent) = configuration.user_agent {
1623        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1624    }
1625    if let Some(ref token) = configuration.bearer_access_token {
1626        req_builder = req_builder.bearer_auth(token.to_owned());
1627    };
1628    req_builder = req_builder.json(&p_body_trust_o_auth2_jwt_grant_issuer);
1629
1630    let req = req_builder.build()?;
1631    let resp = configuration.client.execute(req).await?;
1632
1633    let status = resp.status();
1634    let content_type = resp
1635        .headers()
1636        .get("content-type")
1637        .and_then(|v| v.to_str().ok())
1638        .unwrap_or("application/octet-stream");
1639    let content_type = super::ContentType::from(content_type);
1640
1641    if !status.is_client_error() && !status.is_server_error() {
1642        let content = resp.text().await?;
1643        match content_type {
1644            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1645            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrustedOAuth2JwtGrantIssuer`"))),
1646            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`")))),
1647        }
1648    } else {
1649        let content = resp.text().await?;
1650        let entity: Option<TrustOAuth2JwtGrantIssuerError> = serde_json::from_str(&content).ok();
1651        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1652    }
1653}
1654