Skip to main content

ory_client/apis/
frontend_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.35
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 [`create_browser_login_flow`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateBrowserLoginFlowError {
22    Status400(models::ErrorGeneric),
23    DefaultResponse(models::ErrorGeneric),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`create_browser_logout_flow`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CreateBrowserLogoutFlowError {
31    Status400(models::ErrorGeneric),
32    Status401(models::ErrorGeneric),
33    Status500(models::ErrorGeneric),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`create_browser_recovery_flow`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum CreateBrowserRecoveryFlowError {
41    Status400(models::ErrorGeneric),
42    DefaultResponse(models::ErrorGeneric),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`create_browser_registration_flow`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CreateBrowserRegistrationFlowError {
50    DefaultResponse(models::ErrorGeneric),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`create_browser_settings_flow`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum CreateBrowserSettingsFlowError {
58    Status400(models::ErrorGeneric),
59    Status401(models::ErrorGeneric),
60    Status403(models::ErrorGeneric),
61    DefaultResponse(models::ErrorGeneric),
62    UnknownValue(serde_json::Value),
63}
64
65/// struct for typed errors of method [`create_browser_verification_flow`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum CreateBrowserVerificationFlowError {
69    DefaultResponse(models::ErrorGeneric),
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`create_fedcm_flow`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum CreateFedcmFlowError {
77    Status400(models::ErrorGeneric),
78    DefaultResponse(models::ErrorGeneric),
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method [`create_native_login_flow`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum CreateNativeLoginFlowError {
86    Status400(models::ErrorGeneric),
87    DefaultResponse(models::ErrorGeneric),
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`create_native_recovery_flow`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum CreateNativeRecoveryFlowError {
95    Status400(models::ErrorGeneric),
96    DefaultResponse(models::ErrorGeneric),
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`create_native_registration_flow`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum CreateNativeRegistrationFlowError {
104    Status400(models::ErrorGeneric),
105    DefaultResponse(models::ErrorGeneric),
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`create_native_settings_flow`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum CreateNativeSettingsFlowError {
113    Status400(models::ErrorGeneric),
114    DefaultResponse(models::ErrorGeneric),
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`create_native_verification_flow`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum CreateNativeVerificationFlowError {
122    Status400(models::ErrorGeneric),
123    DefaultResponse(models::ErrorGeneric),
124    UnknownValue(serde_json::Value),
125}
126
127/// struct for typed errors of method [`disable_my_other_sessions`]
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum DisableMyOtherSessionsError {
131    Status400(models::ErrorGeneric),
132    Status401(models::ErrorGeneric),
133    DefaultResponse(models::ErrorGeneric),
134    UnknownValue(serde_json::Value),
135}
136
137/// struct for typed errors of method [`disable_my_session`]
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum DisableMySessionError {
141    Status400(models::ErrorGeneric),
142    Status401(models::ErrorGeneric),
143    DefaultResponse(models::ErrorGeneric),
144    UnknownValue(serde_json::Value),
145}
146
147/// struct for typed errors of method [`exchange_session_token`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum ExchangeSessionTokenError {
151    Status403(models::ErrorGeneric),
152    Status404(models::ErrorGeneric),
153    Status410(models::ErrorGeneric),
154    Status422(models::ErrorGeneric),
155    DefaultResponse(models::ErrorGeneric),
156    UnknownValue(serde_json::Value),
157}
158
159/// struct for typed errors of method [`get_flow_error`]
160#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(untagged)]
162pub enum GetFlowErrorError {
163    Status403(models::ErrorGeneric),
164    Status404(models::ErrorGeneric),
165    Status500(models::ErrorGeneric),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`get_login_flow`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum GetLoginFlowError {
173    Status403(models::ErrorGeneric),
174    Status404(models::ErrorGeneric),
175    Status410(models::ErrorGeneric),
176    DefaultResponse(models::ErrorGeneric),
177    UnknownValue(serde_json::Value),
178}
179
180/// struct for typed errors of method [`get_recovery_flow`]
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum GetRecoveryFlowError {
184    Status404(models::ErrorGeneric),
185    Status410(models::ErrorGeneric),
186    DefaultResponse(models::ErrorGeneric),
187    UnknownValue(serde_json::Value),
188}
189
190/// struct for typed errors of method [`get_registration_flow`]
191#[derive(Debug, Clone, Serialize, Deserialize)]
192#[serde(untagged)]
193pub enum GetRegistrationFlowError {
194    Status403(models::ErrorGeneric),
195    Status404(models::ErrorGeneric),
196    Status410(models::ErrorGeneric),
197    DefaultResponse(models::ErrorGeneric),
198    UnknownValue(serde_json::Value),
199}
200
201/// struct for typed errors of method [`get_settings_flow`]
202#[derive(Debug, Clone, Serialize, Deserialize)]
203#[serde(untagged)]
204pub enum GetSettingsFlowError {
205    Status401(models::ErrorGeneric),
206    Status403(models::ErrorGeneric),
207    Status404(models::ErrorGeneric),
208    Status410(models::ErrorGeneric),
209    DefaultResponse(models::ErrorGeneric),
210    UnknownValue(serde_json::Value),
211}
212
213/// struct for typed errors of method [`get_verification_flow`]
214#[derive(Debug, Clone, Serialize, Deserialize)]
215#[serde(untagged)]
216pub enum GetVerificationFlowError {
217    Status403(models::ErrorGeneric),
218    Status404(models::ErrorGeneric),
219    DefaultResponse(models::ErrorGeneric),
220    UnknownValue(serde_json::Value),
221}
222
223/// struct for typed errors of method [`get_web_authn_java_script`]
224#[derive(Debug, Clone, Serialize, Deserialize)]
225#[serde(untagged)]
226pub enum GetWebAuthnJavaScriptError {
227    UnknownValue(serde_json::Value),
228}
229
230/// struct for typed errors of method [`list_my_sessions`]
231#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum ListMySessionsError {
234    Status400(models::ErrorGeneric),
235    Status401(models::ErrorGeneric),
236    DefaultResponse(models::ErrorGeneric),
237    UnknownValue(serde_json::Value),
238}
239
240/// struct for typed errors of method [`perform_native_logout`]
241#[derive(Debug, Clone, Serialize, Deserialize)]
242#[serde(untagged)]
243pub enum PerformNativeLogoutError {
244    Status400(models::ErrorGeneric),
245    DefaultResponse(models::ErrorGeneric),
246    UnknownValue(serde_json::Value),
247}
248
249/// struct for typed errors of method [`to_session`]
250#[derive(Debug, Clone, Serialize, Deserialize)]
251#[serde(untagged)]
252pub enum ToSessionError {
253    Status401(models::ErrorGeneric),
254    Status403(models::ErrorGeneric),
255    DefaultResponse(models::ErrorGeneric),
256    UnknownValue(serde_json::Value),
257}
258
259/// struct for typed errors of method [`update_fedcm_flow`]
260#[derive(Debug, Clone, Serialize, Deserialize)]
261#[serde(untagged)]
262pub enum UpdateFedcmFlowError {
263    Status400(models::LoginFlow),
264    Status410(models::ErrorGeneric),
265    Status422(models::ErrorBrowserLocationChangeRequired),
266    DefaultResponse(models::ErrorGeneric),
267    UnknownValue(serde_json::Value),
268}
269
270/// struct for typed errors of method [`update_login_flow`]
271#[derive(Debug, Clone, Serialize, Deserialize)]
272#[serde(untagged)]
273pub enum UpdateLoginFlowError {
274    Status400(models::LoginFlow),
275    Status410(models::ErrorGeneric),
276    Status422(models::ErrorBrowserLocationChangeRequired),
277    DefaultResponse(models::ErrorGeneric),
278    UnknownValue(serde_json::Value),
279}
280
281/// struct for typed errors of method [`update_logout_flow`]
282#[derive(Debug, Clone, Serialize, Deserialize)]
283#[serde(untagged)]
284pub enum UpdateLogoutFlowError {
285    DefaultResponse(models::ErrorGeneric),
286    UnknownValue(serde_json::Value),
287}
288
289/// struct for typed errors of method [`update_recovery_flow`]
290#[derive(Debug, Clone, Serialize, Deserialize)]
291#[serde(untagged)]
292pub enum UpdateRecoveryFlowError {
293    Status400(models::RecoveryFlow),
294    Status410(models::ErrorGeneric),
295    Status422(models::ErrorBrowserLocationChangeRequired),
296    DefaultResponse(models::ErrorGeneric),
297    UnknownValue(serde_json::Value),
298}
299
300/// struct for typed errors of method [`update_registration_flow`]
301#[derive(Debug, Clone, Serialize, Deserialize)]
302#[serde(untagged)]
303pub enum UpdateRegistrationFlowError {
304    Status400(models::RegistrationFlow),
305    Status410(models::ErrorGeneric),
306    Status422(models::ErrorBrowserLocationChangeRequired),
307    DefaultResponse(models::ErrorGeneric),
308    UnknownValue(serde_json::Value),
309}
310
311/// struct for typed errors of method [`update_settings_flow`]
312#[derive(Debug, Clone, Serialize, Deserialize)]
313#[serde(untagged)]
314pub enum UpdateSettingsFlowError {
315    Status400(models::SettingsFlow),
316    Status401(models::ErrorGeneric),
317    Status403(models::ErrorGeneric),
318    Status410(models::ErrorGeneric),
319    Status422(models::ErrorBrowserLocationChangeRequired),
320    DefaultResponse(models::ErrorGeneric),
321    UnknownValue(serde_json::Value),
322}
323
324/// struct for typed errors of method [`update_verification_flow`]
325#[derive(Debug, Clone, Serialize, Deserialize)]
326#[serde(untagged)]
327pub enum UpdateVerificationFlowError {
328    Status400(models::VerificationFlow),
329    Status410(models::ErrorGeneric),
330    DefaultResponse(models::ErrorGeneric),
331    UnknownValue(serde_json::Value),
332}
333
334
335/// This endpoint initializes a browser-based user login flow. This endpoint will set the appropriate cookies and anti-CSRF measures required for browser-based flows.  If this endpoint is opened as a link in the browser, it will be redirected to `selfservice.flows.login.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session exists already, the browser will be redirected to `urls.default_redirect_url` unless the query parameter `?refresh=true` was set.  If this endpoint is called via an AJAX request, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `session_already_available`: The user is already signed in. `session_aal1_required`: Multi-factor auth (e.g. 2fa) was requested but the user has no session yet. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `security_identity_mismatch`: The requested `?return_to` address is not allowed to be used. Adjust this in the configuration!  The optional query parameter login_challenge is set when using Kratos with Hydra in an OAuth2 flow. See the oauth2_provider.url configuration option.  This endpoint is NOT INTENDED for clients that do not have a browser (Chrome, Firefox, ...) as cookies are needed.  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
336pub async fn create_browser_login_flow(configuration: &configuration::Configuration, refresh: Option<bool>, aal: Option<&str>, return_to: Option<&str>, cookie: Option<&str>, login_challenge: Option<&str>, organization: Option<&str>, via: Option<&str>, identity_schema: Option<&str>) -> Result<models::LoginFlow, Error<CreateBrowserLoginFlowError>> {
337    // add a prefix to parameters to efficiently prevent name collisions
338    let p_query_refresh = refresh;
339    let p_query_aal = aal;
340    let p_query_return_to = return_to;
341    let p_header_cookie = cookie;
342    let p_query_login_challenge = login_challenge;
343    let p_query_organization = organization;
344    let p_query_via = via;
345    let p_query_identity_schema = identity_schema;
346
347    let uri_str = format!("{}/self-service/login/browser", configuration.base_path);
348    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
349
350    if let Some(ref param_value) = p_query_refresh {
351        req_builder = req_builder.query(&[("refresh", &param_value.to_string())]);
352    }
353    if let Some(ref param_value) = p_query_aal {
354        req_builder = req_builder.query(&[("aal", &param_value.to_string())]);
355    }
356    if let Some(ref param_value) = p_query_return_to {
357        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
358    }
359    if let Some(ref param_value) = p_query_login_challenge {
360        req_builder = req_builder.query(&[("login_challenge", &param_value.to_string())]);
361    }
362    if let Some(ref param_value) = p_query_organization {
363        req_builder = req_builder.query(&[("organization", &param_value.to_string())]);
364    }
365    if let Some(ref param_value) = p_query_via {
366        req_builder = req_builder.query(&[("via", &param_value.to_string())]);
367    }
368    if let Some(ref param_value) = p_query_identity_schema {
369        req_builder = req_builder.query(&[("identity_schema", &param_value.to_string())]);
370    }
371    if let Some(ref user_agent) = configuration.user_agent {
372        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
373    }
374    if let Some(param_value) = p_header_cookie {
375        req_builder = req_builder.header("Cookie", param_value.to_string());
376    }
377
378    let req = req_builder.build()?;
379    let resp = configuration.client.execute(req).await?;
380
381    let status = resp.status();
382    let content_type = resp
383        .headers()
384        .get("content-type")
385        .and_then(|v| v.to_str().ok())
386        .unwrap_or("application/octet-stream");
387    let content_type = super::ContentType::from(content_type);
388
389    if !status.is_client_error() && !status.is_server_error() {
390        let content = resp.text().await?;
391        match content_type {
392            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
393            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginFlow`"))),
394            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::LoginFlow`")))),
395        }
396    } else {
397        let content = resp.text().await?;
398        let entity: Option<CreateBrowserLoginFlowError> = serde_json::from_str(&content).ok();
399        Err(Error::ResponseError(ResponseContent { status, content, entity }))
400    }
401}
402
403/// This endpoint initializes a browser-based user logout flow and a URL which can be used to log out the user.  This endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...). For API clients you can call the `/self-service/logout/api` URL directly with the Ory Session Token.  The URL is only valid for the currently signed in user. If no user is signed in, this endpoint returns a 401 error.  When calling this endpoint from a backend, please ensure to properly forward the HTTP cookies.
404pub async fn create_browser_logout_flow(configuration: &configuration::Configuration, cookie: Option<&str>, return_to: Option<&str>) -> Result<models::LogoutFlow, Error<CreateBrowserLogoutFlowError>> {
405    // add a prefix to parameters to efficiently prevent name collisions
406    let p_header_cookie = cookie;
407    let p_query_return_to = return_to;
408
409    let uri_str = format!("{}/self-service/logout/browser", configuration.base_path);
410    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
411
412    if let Some(ref param_value) = p_query_return_to {
413        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
414    }
415    if let Some(ref user_agent) = configuration.user_agent {
416        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
417    }
418    if let Some(param_value) = p_header_cookie {
419        req_builder = req_builder.header("cookie", param_value.to_string());
420    }
421
422    let req = req_builder.build()?;
423    let resp = configuration.client.execute(req).await?;
424
425    let status = resp.status();
426    let content_type = resp
427        .headers()
428        .get("content-type")
429        .and_then(|v| v.to_str().ok())
430        .unwrap_or("application/octet-stream");
431    let content_type = super::ContentType::from(content_type);
432
433    if !status.is_client_error() && !status.is_server_error() {
434        let content = resp.text().await?;
435        match content_type {
436            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
437            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LogoutFlow`"))),
438            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::LogoutFlow`")))),
439        }
440    } else {
441        let content = resp.text().await?;
442        let entity: Option<CreateBrowserLogoutFlowError> = serde_json::from_str(&content).ok();
443        Err(Error::ResponseError(ResponseContent { status, content, entity }))
444    }
445}
446
447/// This endpoint initializes a browser-based account recovery flow. Once initialized, the browser will be redirected to `selfservice.flows.recovery.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session exists, the browser is returned to the configured return URL.  If this endpoint is called via an AJAX request, the response contains the recovery flow without any redirects or a 400 bad request error if the user is already authenticated.  This endpoint is NOT INTENDED for clients that do not have a browser (Chrome, Firefox, ...) as cookies are needed.  More information can be found at [Ory Kratos Account Recovery Documentation](../self-service/flows/account-recovery).
448pub async fn create_browser_recovery_flow(configuration: &configuration::Configuration, return_to: Option<&str>, skip_settings: Option<&str>) -> Result<models::RecoveryFlow, Error<CreateBrowserRecoveryFlowError>> {
449    // add a prefix to parameters to efficiently prevent name collisions
450    let p_query_return_to = return_to;
451    let p_query_skip_settings = skip_settings;
452
453    let uri_str = format!("{}/self-service/recovery/browser", configuration.base_path);
454    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
455
456    if let Some(ref param_value) = p_query_return_to {
457        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
458    }
459    if let Some(ref param_value) = p_query_skip_settings {
460        req_builder = req_builder.query(&[("skip_settings", &param_value.to_string())]);
461    }
462    if let Some(ref user_agent) = configuration.user_agent {
463        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
464    }
465
466    let req = req_builder.build()?;
467    let resp = configuration.client.execute(req).await?;
468
469    let status = resp.status();
470    let content_type = resp
471        .headers()
472        .get("content-type")
473        .and_then(|v| v.to_str().ok())
474        .unwrap_or("application/octet-stream");
475    let content_type = super::ContentType::from(content_type);
476
477    if !status.is_client_error() && !status.is_server_error() {
478        let content = resp.text().await?;
479        match content_type {
480            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
481            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryFlow`"))),
482            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::RecoveryFlow`")))),
483        }
484    } else {
485        let content = resp.text().await?;
486        let entity: Option<CreateBrowserRecoveryFlowError> = serde_json::from_str(&content).ok();
487        Err(Error::ResponseError(ResponseContent { status, content, entity }))
488    }
489}
490
491/// This endpoint initializes a browser-based user registration flow. This endpoint will set the appropriate cookies and anti-CSRF measures required for browser-based flows.  If this endpoint is opened as a link in the browser, it will be redirected to `selfservice.flows.registration.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session exists already, the browser will be redirected to `urls.default_redirect_url`.  If this endpoint is called via an AJAX request, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `session_already_available`: The user is already signed in. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `security_identity_mismatch`: The requested `?return_to` address is not allowed to be used. Adjust this in the configuration!  If this endpoint is called via an AJAX request, the response contains the registration flow without a redirect.  This endpoint is NOT INTENDED for clients that do not have a browser (Chrome, Firefox, ...) as cookies are needed.  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
492pub async fn create_browser_registration_flow(configuration: &configuration::Configuration, return_to: Option<&str>, login_challenge: Option<&str>, after_verification_return_to: Option<&str>, organization: Option<&str>, identity_schema: Option<&str>) -> Result<models::RegistrationFlow, Error<CreateBrowserRegistrationFlowError>> {
493    // add a prefix to parameters to efficiently prevent name collisions
494    let p_query_return_to = return_to;
495    let p_query_login_challenge = login_challenge;
496    let p_query_after_verification_return_to = after_verification_return_to;
497    let p_query_organization = organization;
498    let p_query_identity_schema = identity_schema;
499
500    let uri_str = format!("{}/self-service/registration/browser", configuration.base_path);
501    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
502
503    if let Some(ref param_value) = p_query_return_to {
504        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
505    }
506    if let Some(ref param_value) = p_query_login_challenge {
507        req_builder = req_builder.query(&[("login_challenge", &param_value.to_string())]);
508    }
509    if let Some(ref param_value) = p_query_after_verification_return_to {
510        req_builder = req_builder.query(&[("after_verification_return_to", &param_value.to_string())]);
511    }
512    if let Some(ref param_value) = p_query_organization {
513        req_builder = req_builder.query(&[("organization", &param_value.to_string())]);
514    }
515    if let Some(ref param_value) = p_query_identity_schema {
516        req_builder = req_builder.query(&[("identity_schema", &param_value.to_string())]);
517    }
518    if let Some(ref user_agent) = configuration.user_agent {
519        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
520    }
521
522    let req = req_builder.build()?;
523    let resp = configuration.client.execute(req).await?;
524
525    let status = resp.status();
526    let content_type = resp
527        .headers()
528        .get("content-type")
529        .and_then(|v| v.to_str().ok())
530        .unwrap_or("application/octet-stream");
531    let content_type = super::ContentType::from(content_type);
532
533    if !status.is_client_error() && !status.is_server_error() {
534        let content = resp.text().await?;
535        match content_type {
536            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
537            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistrationFlow`"))),
538            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::RegistrationFlow`")))),
539        }
540    } else {
541        let content = resp.text().await?;
542        let entity: Option<CreateBrowserRegistrationFlowError> = serde_json::from_str(&content).ok();
543        Err(Error::ResponseError(ResponseContent { status, content, entity }))
544    }
545}
546
547/// This endpoint initializes a browser-based user settings flow. Once initialized, the browser will be redirected to `selfservice.flows.settings.ui_url` with the flow ID set as the query parameter `?flow=`. If no valid Ory Kratos Session Cookie is included in the request, a login flow will be initialized.  If this endpoint is opened as a link in the browser, it will be redirected to `selfservice.flows.settings.ui_url` with the flow ID set as the query parameter `?flow=`. If no valid user session was set, the browser will be redirected to the login endpoint.  If this endpoint is called via an AJAX request, the response contains the settings flow without any redirects or a 401 forbidden error if no valid session was set.  Depending on your configuration this endpoint might return a 403 error if the session has a lower Authenticator Assurance Level (AAL) than is possible for the identity. This can happen if the identity has password + webauthn credentials (which would result in AAL2) but the session has only AAL1. If this error occurs, ask the user to sign in with the second factor (happens automatically for server-side browser flows) or change the configuration.  If this endpoint is called via an AJAX request, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `session_inactive`: No Ory Session was found - sign in a user first. `security_identity_mismatch`: The requested `?return_to` address is not allowed to be used. Adjust this in the configuration!  This endpoint is NOT INTENDED for clients that do not have a browser (Chrome, Firefox, ...) as cookies are needed.  More information can be found at [Ory Kratos User Settings & Profile Management Documentation](../self-service/flows/user-settings).
548pub async fn create_browser_settings_flow(configuration: &configuration::Configuration, return_to: Option<&str>, cookie: Option<&str>) -> Result<models::SettingsFlow, Error<CreateBrowserSettingsFlowError>> {
549    // add a prefix to parameters to efficiently prevent name collisions
550    let p_query_return_to = return_to;
551    let p_header_cookie = cookie;
552
553    let uri_str = format!("{}/self-service/settings/browser", configuration.base_path);
554    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
555
556    if let Some(ref param_value) = p_query_return_to {
557        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
558    }
559    if let Some(ref user_agent) = configuration.user_agent {
560        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
561    }
562    if let Some(param_value) = p_header_cookie {
563        req_builder = req_builder.header("Cookie", param_value.to_string());
564    }
565
566    let req = req_builder.build()?;
567    let resp = configuration.client.execute(req).await?;
568
569    let status = resp.status();
570    let content_type = resp
571        .headers()
572        .get("content-type")
573        .and_then(|v| v.to_str().ok())
574        .unwrap_or("application/octet-stream");
575    let content_type = super::ContentType::from(content_type);
576
577    if !status.is_client_error() && !status.is_server_error() {
578        let content = resp.text().await?;
579        match content_type {
580            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
581            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SettingsFlow`"))),
582            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::SettingsFlow`")))),
583        }
584    } else {
585        let content = resp.text().await?;
586        let entity: Option<CreateBrowserSettingsFlowError> = serde_json::from_str(&content).ok();
587        Err(Error::ResponseError(ResponseContent { status, content, entity }))
588    }
589}
590
591/// This endpoint initializes a browser-based account verification flow. Once initialized, the browser will be redirected to `selfservice.flows.verification.ui_url` with the flow ID set as the query parameter `?flow=`.  If this endpoint is called via an AJAX request, the response contains the recovery flow without any redirects.  This endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).  More information can be found at [Ory Kratos Email and Phone Verification Documentation](https://www.ory.com/docs/kratos/self-service/flows/verify-email-account-activation).
592pub async fn create_browser_verification_flow(configuration: &configuration::Configuration, return_to: Option<&str>) -> Result<models::VerificationFlow, Error<CreateBrowserVerificationFlowError>> {
593    // add a prefix to parameters to efficiently prevent name collisions
594    let p_query_return_to = return_to;
595
596    let uri_str = format!("{}/self-service/verification/browser", configuration.base_path);
597    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
598
599    if let Some(ref param_value) = p_query_return_to {
600        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
601    }
602    if let Some(ref user_agent) = configuration.user_agent {
603        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
604    }
605
606    let req = req_builder.build()?;
607    let resp = configuration.client.execute(req).await?;
608
609    let status = resp.status();
610    let content_type = resp
611        .headers()
612        .get("content-type")
613        .and_then(|v| v.to_str().ok())
614        .unwrap_or("application/octet-stream");
615    let content_type = super::ContentType::from(content_type);
616
617    if !status.is_client_error() && !status.is_server_error() {
618        let content = resp.text().await?;
619        match content_type {
620            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
621            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerificationFlow`"))),
622            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::VerificationFlow`")))),
623        }
624    } else {
625        let content = resp.text().await?;
626        let entity: Option<CreateBrowserVerificationFlowError> = serde_json::from_str(&content).ok();
627        Err(Error::ResponseError(ResponseContent { status, content, entity }))
628    }
629}
630
631/// This endpoint returns a list of all available FedCM providers. It is only supported on the Ory Network.
632pub async fn create_fedcm_flow(configuration: &configuration::Configuration, ) -> Result<models::CreateFedcmFlowResponse, Error<CreateFedcmFlowError>> {
633
634    let uri_str = format!("{}/self-service/fed-cm/parameters", configuration.base_path);
635    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
636
637    if let Some(ref user_agent) = configuration.user_agent {
638        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
639    }
640
641    let req = req_builder.build()?;
642    let resp = configuration.client.execute(req).await?;
643
644    let status = resp.status();
645    let content_type = resp
646        .headers()
647        .get("content-type")
648        .and_then(|v| v.to_str().ok())
649        .unwrap_or("application/octet-stream");
650    let content_type = super::ContentType::from(content_type);
651
652    if !status.is_client_error() && !status.is_server_error() {
653        let content = resp.text().await?;
654        match content_type {
655            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
656            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateFedcmFlowResponse`"))),
657            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::CreateFedcmFlowResponse`")))),
658        }
659    } else {
660        let content = resp.text().await?;
661        let entity: Option<CreateFedcmFlowError> = serde_json::from_str(&content).ok();
662        Err(Error::ResponseError(ResponseContent { status, content, entity }))
663    }
664}
665
666/// This endpoint initiates a login flow for native apps that do not use a browser, such as mobile devices, smart TVs, and so on.  If a valid provided session cookie or session token is provided, a 400 Bad Request error will be returned unless the URL query parameter `?refresh=true` is set.  To fetch an existing login flow call `/self-service/login/flows?flow=<flow_id>`.  You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make you vulnerable to a variety of CSRF attacks, including CSRF login attacks.  In the case of an error, the `error.id` of the JSON response body can be one of:  `session_already_available`: The user is already signed in. `session_aal1_required`: Multi-factor auth (e.g. 2fa) was requested but the user has no session yet. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred.  This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
667pub async fn create_native_login_flow(configuration: &configuration::Configuration, refresh: Option<bool>, aal: Option<&str>, x_session_token: Option<&str>, return_session_token_exchange_code: Option<bool>, return_to: Option<&str>, organization: Option<&str>, via: Option<&str>, identity_schema: Option<&str>) -> Result<models::LoginFlow, Error<CreateNativeLoginFlowError>> {
668    // add a prefix to parameters to efficiently prevent name collisions
669    let p_query_refresh = refresh;
670    let p_query_aal = aal;
671    let p_header_x_session_token = x_session_token;
672    let p_query_return_session_token_exchange_code = return_session_token_exchange_code;
673    let p_query_return_to = return_to;
674    let p_query_organization = organization;
675    let p_query_via = via;
676    let p_query_identity_schema = identity_schema;
677
678    let uri_str = format!("{}/self-service/login/api", configuration.base_path);
679    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
680
681    if let Some(ref param_value) = p_query_refresh {
682        req_builder = req_builder.query(&[("refresh", &param_value.to_string())]);
683    }
684    if let Some(ref param_value) = p_query_aal {
685        req_builder = req_builder.query(&[("aal", &param_value.to_string())]);
686    }
687    if let Some(ref param_value) = p_query_return_session_token_exchange_code {
688        req_builder = req_builder.query(&[("return_session_token_exchange_code", &param_value.to_string())]);
689    }
690    if let Some(ref param_value) = p_query_return_to {
691        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
692    }
693    if let Some(ref param_value) = p_query_organization {
694        req_builder = req_builder.query(&[("organization", &param_value.to_string())]);
695    }
696    if let Some(ref param_value) = p_query_via {
697        req_builder = req_builder.query(&[("via", &param_value.to_string())]);
698    }
699    if let Some(ref param_value) = p_query_identity_schema {
700        req_builder = req_builder.query(&[("identity_schema", &param_value.to_string())]);
701    }
702    if let Some(ref user_agent) = configuration.user_agent {
703        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
704    }
705    if let Some(param_value) = p_header_x_session_token {
706        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
707    }
708
709    let req = req_builder.build()?;
710    let resp = configuration.client.execute(req).await?;
711
712    let status = resp.status();
713    let content_type = resp
714        .headers()
715        .get("content-type")
716        .and_then(|v| v.to_str().ok())
717        .unwrap_or("application/octet-stream");
718    let content_type = super::ContentType::from(content_type);
719
720    if !status.is_client_error() && !status.is_server_error() {
721        let content = resp.text().await?;
722        match content_type {
723            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
724            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginFlow`"))),
725            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::LoginFlow`")))),
726        }
727    } else {
728        let content = resp.text().await?;
729        let entity: Option<CreateNativeLoginFlowError> = serde_json::from_str(&content).ok();
730        Err(Error::ResponseError(ResponseContent { status, content, entity }))
731    }
732}
733
734/// This endpoint initiates a recovery flow for API clients such as mobile devices, smart TVs, and so on.  If a valid provided session cookie or session token is provided, a 400 Bad Request error.  On an existing recovery flow, use the `getRecoveryFlow` API endpoint.  You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make you vulnerable to a variety of CSRF attacks.  This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).  More information can be found at [Ory Kratos Account Recovery Documentation](../self-service/flows/account-recovery).
735pub async fn create_native_recovery_flow(configuration: &configuration::Configuration, ) -> Result<models::RecoveryFlow, Error<CreateNativeRecoveryFlowError>> {
736
737    let uri_str = format!("{}/self-service/recovery/api", configuration.base_path);
738    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
739
740    if let Some(ref user_agent) = configuration.user_agent {
741        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
742    }
743
744    let req = req_builder.build()?;
745    let resp = configuration.client.execute(req).await?;
746
747    let status = resp.status();
748    let content_type = resp
749        .headers()
750        .get("content-type")
751        .and_then(|v| v.to_str().ok())
752        .unwrap_or("application/octet-stream");
753    let content_type = super::ContentType::from(content_type);
754
755    if !status.is_client_error() && !status.is_server_error() {
756        let content = resp.text().await?;
757        match content_type {
758            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
759            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryFlow`"))),
760            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::RecoveryFlow`")))),
761        }
762    } else {
763        let content = resp.text().await?;
764        let entity: Option<CreateNativeRecoveryFlowError> = serde_json::from_str(&content).ok();
765        Err(Error::ResponseError(ResponseContent { status, content, entity }))
766    }
767}
768
769/// This endpoint initiates a registration flow for API clients such as mobile devices, smart TVs, and so on.  If a valid provided session cookie or session token is provided, a 400 Bad Request error will be returned unless the URL query parameter `?refresh=true` is set.  To fetch an existing registration flow call `/self-service/registration/flows?flow=<flow_id>`.  You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make you vulnerable to a variety of CSRF attacks.  In the case of an error, the `error.id` of the JSON response body can be one of:  `session_already_available`: The user is already signed in. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred.  This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
770pub async fn create_native_registration_flow(configuration: &configuration::Configuration, return_session_token_exchange_code: Option<bool>, return_to: Option<&str>, organization: Option<&str>, identity_schema: Option<&str>) -> Result<models::RegistrationFlow, Error<CreateNativeRegistrationFlowError>> {
771    // add a prefix to parameters to efficiently prevent name collisions
772    let p_query_return_session_token_exchange_code = return_session_token_exchange_code;
773    let p_query_return_to = return_to;
774    let p_query_organization = organization;
775    let p_query_identity_schema = identity_schema;
776
777    let uri_str = format!("{}/self-service/registration/api", configuration.base_path);
778    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
779
780    if let Some(ref param_value) = p_query_return_session_token_exchange_code {
781        req_builder = req_builder.query(&[("return_session_token_exchange_code", &param_value.to_string())]);
782    }
783    if let Some(ref param_value) = p_query_return_to {
784        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
785    }
786    if let Some(ref param_value) = p_query_organization {
787        req_builder = req_builder.query(&[("organization", &param_value.to_string())]);
788    }
789    if let Some(ref param_value) = p_query_identity_schema {
790        req_builder = req_builder.query(&[("identity_schema", &param_value.to_string())]);
791    }
792    if let Some(ref user_agent) = configuration.user_agent {
793        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
794    }
795
796    let req = req_builder.build()?;
797    let resp = configuration.client.execute(req).await?;
798
799    let status = resp.status();
800    let content_type = resp
801        .headers()
802        .get("content-type")
803        .and_then(|v| v.to_str().ok())
804        .unwrap_or("application/octet-stream");
805    let content_type = super::ContentType::from(content_type);
806
807    if !status.is_client_error() && !status.is_server_error() {
808        let content = resp.text().await?;
809        match content_type {
810            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
811            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistrationFlow`"))),
812            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::RegistrationFlow`")))),
813        }
814    } else {
815        let content = resp.text().await?;
816        let entity: Option<CreateNativeRegistrationFlowError> = serde_json::from_str(&content).ok();
817        Err(Error::ResponseError(ResponseContent { status, content, entity }))
818    }
819}
820
821/// This endpoint initiates a settings flow for API clients such as mobile devices, smart TVs, and so on. You must provide a valid Ory Kratos Session Token for this endpoint to respond with HTTP 200 OK.  To fetch an existing settings flow call `/self-service/settings/flows?flow=<flow_id>`.  You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make you vulnerable to a variety of CSRF attacks.  Depending on your configuration this endpoint might return a 403 error if the session has a lower Authenticator Assurance Level (AAL) than is possible for the identity. This can happen if the identity has password + webauthn credentials (which would result in AAL2) but the session has only AAL1. If this error occurs, ask the user to sign in with the second factor or change the configuration.  In the case of an error, the `error.id` of the JSON response body can be one of:  `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `session_inactive`: No Ory Session was found - sign in a user first.  This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).  More information can be found at [Ory Kratos User Settings & Profile Management Documentation](../self-service/flows/user-settings).
822pub async fn create_native_settings_flow(configuration: &configuration::Configuration, x_session_token: Option<&str>) -> Result<models::SettingsFlow, Error<CreateNativeSettingsFlowError>> {
823    // add a prefix to parameters to efficiently prevent name collisions
824    let p_header_x_session_token = x_session_token;
825
826    let uri_str = format!("{}/self-service/settings/api", configuration.base_path);
827    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
828
829    if let Some(ref user_agent) = configuration.user_agent {
830        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
831    }
832    if let Some(param_value) = p_header_x_session_token {
833        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
834    }
835
836    let req = req_builder.build()?;
837    let resp = configuration.client.execute(req).await?;
838
839    let status = resp.status();
840    let content_type = resp
841        .headers()
842        .get("content-type")
843        .and_then(|v| v.to_str().ok())
844        .unwrap_or("application/octet-stream");
845    let content_type = super::ContentType::from(content_type);
846
847    if !status.is_client_error() && !status.is_server_error() {
848        let content = resp.text().await?;
849        match content_type {
850            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
851            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SettingsFlow`"))),
852            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::SettingsFlow`")))),
853        }
854    } else {
855        let content = resp.text().await?;
856        let entity: Option<CreateNativeSettingsFlowError> = serde_json::from_str(&content).ok();
857        Err(Error::ResponseError(ResponseContent { status, content, entity }))
858    }
859}
860
861/// This endpoint initiates a verification flow for API clients such as mobile devices, smart TVs, and so on.  To fetch an existing verification flow call `/self-service/verification/flows?flow=<flow_id>`.  You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make you vulnerable to a variety of CSRF attacks.  This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).  More information can be found at [Ory Email and Phone Verification Documentation](https://www.ory.com/docs/kratos/self-service/flows/verify-email-account-activation).
862pub async fn create_native_verification_flow(configuration: &configuration::Configuration, return_to: Option<&str>) -> Result<models::VerificationFlow, Error<CreateNativeVerificationFlowError>> {
863    // add a prefix to parameters to efficiently prevent name collisions
864    let p_query_return_to = return_to;
865
866    let uri_str = format!("{}/self-service/verification/api", configuration.base_path);
867    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
868
869    if let Some(ref param_value) = p_query_return_to {
870        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
871    }
872    if let Some(ref user_agent) = configuration.user_agent {
873        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
874    }
875
876    let req = req_builder.build()?;
877    let resp = configuration.client.execute(req).await?;
878
879    let status = resp.status();
880    let content_type = resp
881        .headers()
882        .get("content-type")
883        .and_then(|v| v.to_str().ok())
884        .unwrap_or("application/octet-stream");
885    let content_type = super::ContentType::from(content_type);
886
887    if !status.is_client_error() && !status.is_server_error() {
888        let content = resp.text().await?;
889        match content_type {
890            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
891            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerificationFlow`"))),
892            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::VerificationFlow`")))),
893        }
894    } else {
895        let content = resp.text().await?;
896        let entity: Option<CreateNativeVerificationFlowError> = serde_json::from_str(&content).ok();
897        Err(Error::ResponseError(ResponseContent { status, content, entity }))
898    }
899}
900
901/// Calling this endpoint invalidates all except the current session that belong to the logged-in user. Session data are not deleted.
902pub async fn disable_my_other_sessions(configuration: &configuration::Configuration, x_session_token: Option<&str>, cookie: Option<&str>) -> Result<models::DeleteMySessionsCount, Error<DisableMyOtherSessionsError>> {
903    // add a prefix to parameters to efficiently prevent name collisions
904    let p_header_x_session_token = x_session_token;
905    let p_header_cookie = cookie;
906
907    let uri_str = format!("{}/sessions", configuration.base_path);
908    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
909
910    if let Some(ref user_agent) = configuration.user_agent {
911        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
912    }
913    if let Some(param_value) = p_header_x_session_token {
914        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
915    }
916    if let Some(param_value) = p_header_cookie {
917        req_builder = req_builder.header("Cookie", param_value.to_string());
918    }
919
920    let req = req_builder.build()?;
921    let resp = configuration.client.execute(req).await?;
922
923    let status = resp.status();
924    let content_type = resp
925        .headers()
926        .get("content-type")
927        .and_then(|v| v.to_str().ok())
928        .unwrap_or("application/octet-stream");
929    let content_type = super::ContentType::from(content_type);
930
931    if !status.is_client_error() && !status.is_server_error() {
932        let content = resp.text().await?;
933        match content_type {
934            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
935            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteMySessionsCount`"))),
936            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::DeleteMySessionsCount`")))),
937        }
938    } else {
939        let content = resp.text().await?;
940        let entity: Option<DisableMyOtherSessionsError> = serde_json::from_str(&content).ok();
941        Err(Error::ResponseError(ResponseContent { status, content, entity }))
942    }
943}
944
945/// Calling this endpoint invalidates the specified session. The current session cannot be revoked. Session data are not deleted.
946pub async fn disable_my_session(configuration: &configuration::Configuration, id: &str, x_session_token: Option<&str>, cookie: Option<&str>) -> Result<(), Error<DisableMySessionError>> {
947    // add a prefix to parameters to efficiently prevent name collisions
948    let p_path_id = id;
949    let p_header_x_session_token = x_session_token;
950    let p_header_cookie = cookie;
951
952    let uri_str = format!("{}/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
953    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
954
955    if let Some(ref user_agent) = configuration.user_agent {
956        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
957    }
958    if let Some(param_value) = p_header_x_session_token {
959        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
960    }
961    if let Some(param_value) = p_header_cookie {
962        req_builder = req_builder.header("Cookie", param_value.to_string());
963    }
964
965    let req = req_builder.build()?;
966    let resp = configuration.client.execute(req).await?;
967
968    let status = resp.status();
969
970    if !status.is_client_error() && !status.is_server_error() {
971        Ok(())
972    } else {
973        let content = resp.text().await?;
974        let entity: Option<DisableMySessionError> = serde_json::from_str(&content).ok();
975        Err(Error::ResponseError(ResponseContent { status, content, entity }))
976    }
977}
978
979pub async fn exchange_session_token(configuration: &configuration::Configuration, init_code: &str, return_to_code: &str) -> Result<models::SuccessfulNativeLogin, Error<ExchangeSessionTokenError>> {
980    // add a prefix to parameters to efficiently prevent name collisions
981    let p_query_init_code = init_code;
982    let p_query_return_to_code = return_to_code;
983
984    let uri_str = format!("{}/sessions/token-exchange", configuration.base_path);
985    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
986
987    req_builder = req_builder.query(&[("init_code", &p_query_init_code.to_string())]);
988    req_builder = req_builder.query(&[("return_to_code", &p_query_return_to_code.to_string())]);
989    if let Some(ref user_agent) = configuration.user_agent {
990        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
991    }
992
993    let req = req_builder.build()?;
994    let resp = configuration.client.execute(req).await?;
995
996    let status = resp.status();
997    let content_type = resp
998        .headers()
999        .get("content-type")
1000        .and_then(|v| v.to_str().ok())
1001        .unwrap_or("application/octet-stream");
1002    let content_type = super::ContentType::from(content_type);
1003
1004    if !status.is_client_error() && !status.is_server_error() {
1005        let content = resp.text().await?;
1006        match content_type {
1007            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1008            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SuccessfulNativeLogin`"))),
1009            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::SuccessfulNativeLogin`")))),
1010        }
1011    } else {
1012        let content = resp.text().await?;
1013        let entity: Option<ExchangeSessionTokenError> = serde_json::from_str(&content).ok();
1014        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1015    }
1016}
1017
1018/// This endpoint returns the error associated with a user-facing self service errors.  This endpoint supports stub values to help you implement the error UI:  `?id=stub:500` - returns a stub 500 (Internal Server Error) error.  More information can be found at [Ory Kratos User User Facing Error Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-facing-errors).
1019pub async fn get_flow_error(configuration: &configuration::Configuration, id: &str) -> Result<models::FlowError, Error<GetFlowErrorError>> {
1020    // add a prefix to parameters to efficiently prevent name collisions
1021    let p_query_id = id;
1022
1023    let uri_str = format!("{}/self-service/errors", configuration.base_path);
1024    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1025
1026    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
1027    if let Some(ref user_agent) = configuration.user_agent {
1028        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1029    }
1030
1031    let req = req_builder.build()?;
1032    let resp = configuration.client.execute(req).await?;
1033
1034    let status = resp.status();
1035    let content_type = resp
1036        .headers()
1037        .get("content-type")
1038        .and_then(|v| v.to_str().ok())
1039        .unwrap_or("application/octet-stream");
1040    let content_type = super::ContentType::from(content_type);
1041
1042    if !status.is_client_error() && !status.is_server_error() {
1043        let content = resp.text().await?;
1044        match content_type {
1045            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1046            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FlowError`"))),
1047            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::FlowError`")))),
1048        }
1049    } else {
1050        let content = resp.text().await?;
1051        let entity: Option<GetFlowErrorError> = serde_json::from_str(&content).ok();
1052        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1053    }
1054}
1055
1056/// This endpoint returns a login flow's context with, for example, error details and other information.  Browser flows expect the anti-CSRF cookie to be included in the request's HTTP Cookie Header. For AJAX requests you must ensure that cookies are included in the request or requests will fail.  If you use the browser-flow for server-side apps, the services need to run on a common top-level-domain and you need to forward the incoming HTTP Cookie header to this endpoint:  ```js pseudo-code example router.get('/login', async function (req, res) { const flow = await client.getLoginFlow(req.header('cookie'), req.query['flow'])  res.render('login', flow) }) ```  This request may fail due to several reasons. The `error.id` can be one of:  `session_already_available`: The user is already signed in. `self_service_flow_expired`: The flow is expired and you should request a new one.  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
1057pub async fn get_login_flow(configuration: &configuration::Configuration, id: &str, cookie: Option<&str>) -> Result<models::LoginFlow, Error<GetLoginFlowError>> {
1058    // add a prefix to parameters to efficiently prevent name collisions
1059    let p_query_id = id;
1060    let p_header_cookie = cookie;
1061
1062    let uri_str = format!("{}/self-service/login/flows", configuration.base_path);
1063    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1064
1065    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
1066    if let Some(ref user_agent) = configuration.user_agent {
1067        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1068    }
1069    if let Some(param_value) = p_header_cookie {
1070        req_builder = req_builder.header("Cookie", param_value.to_string());
1071    }
1072
1073    let req = req_builder.build()?;
1074    let resp = configuration.client.execute(req).await?;
1075
1076    let status = resp.status();
1077    let content_type = resp
1078        .headers()
1079        .get("content-type")
1080        .and_then(|v| v.to_str().ok())
1081        .unwrap_or("application/octet-stream");
1082    let content_type = super::ContentType::from(content_type);
1083
1084    if !status.is_client_error() && !status.is_server_error() {
1085        let content = resp.text().await?;
1086        match content_type {
1087            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1088            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginFlow`"))),
1089            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::LoginFlow`")))),
1090        }
1091    } else {
1092        let content = resp.text().await?;
1093        let entity: Option<GetLoginFlowError> = serde_json::from_str(&content).ok();
1094        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1095    }
1096}
1097
1098/// This endpoint returns a recovery flow's context with, for example, error details and other information.  Browser flows expect the anti-CSRF cookie to be included in the request's HTTP Cookie Header. For AJAX requests you must ensure that cookies are included in the request or requests will fail.  If you use the browser-flow for server-side apps, the services need to run on a common top-level-domain and you need to forward the incoming HTTP Cookie header to this endpoint:  ```js pseudo-code example router.get('/recovery', async function (req, res) { const flow = await client.getRecoveryFlow(req.header('Cookie'), req.query['flow'])  res.render('recovery', flow) }) ```  More information can be found at [Ory Kratos Account Recovery Documentation](../self-service/flows/account-recovery).
1099pub async fn get_recovery_flow(configuration: &configuration::Configuration, id: &str, cookie: Option<&str>) -> Result<models::RecoveryFlow, Error<GetRecoveryFlowError>> {
1100    // add a prefix to parameters to efficiently prevent name collisions
1101    let p_query_id = id;
1102    let p_header_cookie = cookie;
1103
1104    let uri_str = format!("{}/self-service/recovery/flows", configuration.base_path);
1105    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1106
1107    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
1108    if let Some(ref user_agent) = configuration.user_agent {
1109        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1110    }
1111    if let Some(param_value) = p_header_cookie {
1112        req_builder = req_builder.header("Cookie", param_value.to_string());
1113    }
1114
1115    let req = req_builder.build()?;
1116    let resp = configuration.client.execute(req).await?;
1117
1118    let status = resp.status();
1119    let content_type = resp
1120        .headers()
1121        .get("content-type")
1122        .and_then(|v| v.to_str().ok())
1123        .unwrap_or("application/octet-stream");
1124    let content_type = super::ContentType::from(content_type);
1125
1126    if !status.is_client_error() && !status.is_server_error() {
1127        let content = resp.text().await?;
1128        match content_type {
1129            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1130            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryFlow`"))),
1131            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::RecoveryFlow`")))),
1132        }
1133    } else {
1134        let content = resp.text().await?;
1135        let entity: Option<GetRecoveryFlowError> = serde_json::from_str(&content).ok();
1136        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1137    }
1138}
1139
1140/// This endpoint returns a registration flow's context with, for example, error details and other information.  Browser flows expect the anti-CSRF cookie to be included in the request's HTTP Cookie Header. For AJAX requests you must ensure that cookies are included in the request or requests will fail.  If you use the browser-flow for server-side apps, the services need to run on a common top-level-domain and you need to forward the incoming HTTP Cookie header to this endpoint:  ```js pseudo-code example router.get('/registration', async function (req, res) { const flow = await client.getRegistrationFlow(req.header('cookie'), req.query['flow'])  res.render('registration', flow) }) ```  This request may fail due to several reasons. The `error.id` can be one of:  `session_already_available`: The user is already signed in. `self_service_flow_expired`: The flow is expired and you should request a new one.  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
1141pub async fn get_registration_flow(configuration: &configuration::Configuration, id: &str, cookie: Option<&str>) -> Result<models::RegistrationFlow, Error<GetRegistrationFlowError>> {
1142    // add a prefix to parameters to efficiently prevent name collisions
1143    let p_query_id = id;
1144    let p_header_cookie = cookie;
1145
1146    let uri_str = format!("{}/self-service/registration/flows", configuration.base_path);
1147    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1148
1149    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
1150    if let Some(ref user_agent) = configuration.user_agent {
1151        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1152    }
1153    if let Some(param_value) = p_header_cookie {
1154        req_builder = req_builder.header("Cookie", param_value.to_string());
1155    }
1156
1157    let req = req_builder.build()?;
1158    let resp = configuration.client.execute(req).await?;
1159
1160    let status = resp.status();
1161    let content_type = resp
1162        .headers()
1163        .get("content-type")
1164        .and_then(|v| v.to_str().ok())
1165        .unwrap_or("application/octet-stream");
1166    let content_type = super::ContentType::from(content_type);
1167
1168    if !status.is_client_error() && !status.is_server_error() {
1169        let content = resp.text().await?;
1170        match content_type {
1171            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1172            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistrationFlow`"))),
1173            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::RegistrationFlow`")))),
1174        }
1175    } else {
1176        let content = resp.text().await?;
1177        let entity: Option<GetRegistrationFlowError> = serde_json::from_str(&content).ok();
1178        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1179    }
1180}
1181
1182/// When accessing this endpoint through Ory Kratos' Public API you must ensure that either the Ory Kratos Session Cookie or the Ory Kratos Session Token are set.  Depending on your configuration this endpoint might return a 403 error if the session has a lower Authenticator Assurance Level (AAL) than is possible for the identity. This can happen if the identity has password + webauthn credentials (which would result in AAL2) but the session has only AAL1. If this error occurs, ask the user to sign in with the second factor or change the configuration.  You can access this endpoint without credentials when using Ory Kratos' Admin API.  If this endpoint is called via an AJAX request, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `session_inactive`: No Ory Session was found - sign in a user first. `security_identity_mismatch`: The flow was interrupted with `session_refresh_required` but apparently some other identity logged in instead.  More information can be found at [Ory Kratos User Settings & Profile Management Documentation](../self-service/flows/user-settings).
1183pub async fn get_settings_flow(configuration: &configuration::Configuration, id: &str, x_session_token: Option<&str>, cookie: Option<&str>) -> Result<models::SettingsFlow, Error<GetSettingsFlowError>> {
1184    // add a prefix to parameters to efficiently prevent name collisions
1185    let p_query_id = id;
1186    let p_header_x_session_token = x_session_token;
1187    let p_header_cookie = cookie;
1188
1189    let uri_str = format!("{}/self-service/settings/flows", configuration.base_path);
1190    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1191
1192    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
1193    if let Some(ref user_agent) = configuration.user_agent {
1194        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1195    }
1196    if let Some(param_value) = p_header_x_session_token {
1197        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
1198    }
1199    if let Some(param_value) = p_header_cookie {
1200        req_builder = req_builder.header("Cookie", param_value.to_string());
1201    }
1202
1203    let req = req_builder.build()?;
1204    let resp = configuration.client.execute(req).await?;
1205
1206    let status = resp.status();
1207    let content_type = resp
1208        .headers()
1209        .get("content-type")
1210        .and_then(|v| v.to_str().ok())
1211        .unwrap_or("application/octet-stream");
1212    let content_type = super::ContentType::from(content_type);
1213
1214    if !status.is_client_error() && !status.is_server_error() {
1215        let content = resp.text().await?;
1216        match content_type {
1217            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1218            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SettingsFlow`"))),
1219            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::SettingsFlow`")))),
1220        }
1221    } else {
1222        let content = resp.text().await?;
1223        let entity: Option<GetSettingsFlowError> = serde_json::from_str(&content).ok();
1224        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1225    }
1226}
1227
1228/// This endpoint returns a verification flow's context with, for example, error details and other information.  Browser flows expect the anti-CSRF cookie to be included in the request's HTTP Cookie Header. For AJAX requests you must ensure that cookies are included in the request or requests will fail.  If you use the browser-flow for server-side apps, the services need to run on a common top-level-domain and you need to forward the incoming HTTP Cookie header to this endpoint:  ```js pseudo-code example router.get('/recovery', async function (req, res) { const flow = await client.getVerificationFlow(req.header('cookie'), req.query['flow'])  res.render('verification', flow) }) ```  More information can be found at [Ory Kratos Email and Phone Verification Documentation](https://www.ory.com/docs/kratos/self-service/flows/verify-email-account-activation).
1229pub async fn get_verification_flow(configuration: &configuration::Configuration, id: &str, cookie: Option<&str>) -> Result<models::VerificationFlow, Error<GetVerificationFlowError>> {
1230    // add a prefix to parameters to efficiently prevent name collisions
1231    let p_query_id = id;
1232    let p_header_cookie = cookie;
1233
1234    let uri_str = format!("{}/self-service/verification/flows", configuration.base_path);
1235    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1236
1237    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
1238    if let Some(ref user_agent) = configuration.user_agent {
1239        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1240    }
1241    if let Some(param_value) = p_header_cookie {
1242        req_builder = req_builder.header("cookie", param_value.to_string());
1243    }
1244
1245    let req = req_builder.build()?;
1246    let resp = configuration.client.execute(req).await?;
1247
1248    let status = resp.status();
1249    let content_type = resp
1250        .headers()
1251        .get("content-type")
1252        .and_then(|v| v.to_str().ok())
1253        .unwrap_or("application/octet-stream");
1254    let content_type = super::ContentType::from(content_type);
1255
1256    if !status.is_client_error() && !status.is_server_error() {
1257        let content = resp.text().await?;
1258        match content_type {
1259            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1260            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerificationFlow`"))),
1261            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::VerificationFlow`")))),
1262        }
1263    } else {
1264        let content = resp.text().await?;
1265        let entity: Option<GetVerificationFlowError> = serde_json::from_str(&content).ok();
1266        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1267    }
1268}
1269
1270/// This endpoint provides JavaScript which is needed in order to perform WebAuthn login and registration.  If you are building a JavaScript Browser App (e.g. in ReactJS or AngularJS) you will need to load this file:  ```html <script src=\"https://public-kratos.example.org/.well-known/ory/webauthn.js\" type=\"script\" async /> ```  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
1271pub async fn get_web_authn_java_script(configuration: &configuration::Configuration, ) -> Result<String, Error<GetWebAuthnJavaScriptError>> {
1272
1273    let uri_str = format!("{}/.well-known/ory/webauthn.js", configuration.base_path);
1274    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1275
1276    if let Some(ref user_agent) = configuration.user_agent {
1277        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1278    }
1279
1280    let req = req_builder.build()?;
1281    let resp = configuration.client.execute(req).await?;
1282
1283    let status = resp.status();
1284    let content_type = resp
1285        .headers()
1286        .get("content-type")
1287        .and_then(|v| v.to_str().ok())
1288        .unwrap_or("application/octet-stream");
1289    let content_type = super::ContentType::from(content_type);
1290
1291    if !status.is_client_error() && !status.is_server_error() {
1292        let content = resp.text().await?;
1293        match content_type {
1294            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1295            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
1296            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
1297        }
1298    } else {
1299        let content = resp.text().await?;
1300        let entity: Option<GetWebAuthnJavaScriptError> = serde_json::from_str(&content).ok();
1301        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1302    }
1303}
1304
1305/// This endpoints returns all other active sessions that belong to the logged-in user. The current session can be retrieved by calling the `/sessions/whoami` endpoint.
1306pub async fn list_my_sessions(configuration: &configuration::Configuration, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>, x_session_token: Option<&str>, cookie: Option<&str>) -> Result<Vec<models::Session>, Error<ListMySessionsError>> {
1307    // add a prefix to parameters to efficiently prevent name collisions
1308    let p_query_per_page = per_page;
1309    let p_query_page = page;
1310    let p_query_page_size = page_size;
1311    let p_query_page_token = page_token;
1312    let p_header_x_session_token = x_session_token;
1313    let p_header_cookie = cookie;
1314
1315    let uri_str = format!("{}/sessions", configuration.base_path);
1316    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1317
1318    if let Some(ref param_value) = p_query_per_page {
1319        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
1320    }
1321    if let Some(ref param_value) = p_query_page {
1322        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
1323    }
1324    if let Some(ref param_value) = p_query_page_size {
1325        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
1326    }
1327    if let Some(ref param_value) = p_query_page_token {
1328        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
1329    }
1330    if let Some(ref user_agent) = configuration.user_agent {
1331        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1332    }
1333    if let Some(param_value) = p_header_x_session_token {
1334        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
1335    }
1336    if let Some(param_value) = p_header_cookie {
1337        req_builder = req_builder.header("Cookie", param_value.to_string());
1338    }
1339
1340    let req = req_builder.build()?;
1341    let resp = configuration.client.execute(req).await?;
1342
1343    let status = resp.status();
1344    let content_type = resp
1345        .headers()
1346        .get("content-type")
1347        .and_then(|v| v.to_str().ok())
1348        .unwrap_or("application/octet-stream");
1349    let content_type = super::ContentType::from(content_type);
1350
1351    if !status.is_client_error() && !status.is_server_error() {
1352        let content = resp.text().await?;
1353        match content_type {
1354            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1355            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Session&gt;`"))),
1356            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::Session&gt;`")))),
1357        }
1358    } else {
1359        let content = resp.text().await?;
1360        let entity: Option<ListMySessionsError> = serde_json::from_str(&content).ok();
1361        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1362    }
1363}
1364
1365/// Use this endpoint to log out an identity using an Ory Session Token. If the Ory Session Token was successfully revoked, the server returns a 204 No Content response. A 204 No Content response is also sent when the Ory Session Token has been revoked already before.  If the Ory Session Token is malformed or does not exist a 403 Forbidden response will be returned.  This endpoint does not remove any HTTP Cookies - use the Browser-Based Self-Service Logout Flow instead.
1366pub async fn perform_native_logout(configuration: &configuration::Configuration, perform_native_logout_body: models::PerformNativeLogoutBody) -> Result<(), Error<PerformNativeLogoutError>> {
1367    // add a prefix to parameters to efficiently prevent name collisions
1368    let p_body_perform_native_logout_body = perform_native_logout_body;
1369
1370    let uri_str = format!("{}/self-service/logout/api", configuration.base_path);
1371    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
1372
1373    if let Some(ref user_agent) = configuration.user_agent {
1374        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1375    }
1376    req_builder = req_builder.json(&p_body_perform_native_logout_body);
1377
1378    let req = req_builder.build()?;
1379    let resp = configuration.client.execute(req).await?;
1380
1381    let status = resp.status();
1382
1383    if !status.is_client_error() && !status.is_server_error() {
1384        Ok(())
1385    } else {
1386        let content = resp.text().await?;
1387        let entity: Option<PerformNativeLogoutError> = serde_json::from_str(&content).ok();
1388        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1389    }
1390}
1391
1392/// Uses the HTTP Headers in the GET request to determine (e.g. by using checking the cookies) who is authenticated. Returns a session object in the body or 401 if the credentials are invalid or no credentials were sent. When the request it successful it adds the user ID to the 'X-Kratos-Authenticated-Identity-Id' header in the response.  If you call this endpoint from a server-side application, you must forward the HTTP Cookie Header to this endpoint:  ```js pseudo-code example router.get('/protected-endpoint', async function (req, res) { const session = await client.toSession(undefined, req.header('cookie'))  console.log(session) }) ```  When calling this endpoint from a non-browser application (e.g. mobile app) you must include the session token:  ```js pseudo-code example ... const session = await client.toSession(\"the-session-token\")  console.log(session) ```  When using a token template, the token is included in the `tokenized` field of the session.  ```js pseudo-code example ... const session = await client.toSession(\"the-session-token\", { tokenize_as: \"example-jwt-template\" })  console.log(session.tokenized) // The JWT ```  Depending on your configuration this endpoint might return a 403 status code if the session has a lower Authenticator Assurance Level (AAL) than is possible for the identity. This can happen if the identity has password + webauthn credentials (which would result in AAL2) but the session has only AAL1. If this error occurs, ask the user to sign in with the second factor or change the configuration.  This endpoint is useful for:  AJAX calls. Remember to send credentials and set up CORS correctly! Reverse proxies and API Gateways Server-side calls - use the `X-Session-Token` header!  This endpoint authenticates users by checking:  if the `Cookie` HTTP header was set containing an Ory Kratos Session Cookie; if the `Authorization: bearer <ory-session-token>` HTTP header was set with a valid Ory Kratos Session Token; if the `X-Session-Token` HTTP header was set with a valid Ory Kratos Session Token.  If none of these headers are set or the cookie or token are invalid, the endpoint returns a HTTP 401 status code.  As explained above, this request may fail due to several reasons. The `error.id` can be one of:  `session_inactive`: No active session was found in the request (e.g. no Ory Session Cookie / Ory Session Token). `session_aal2_required`: An active session was found but it does not fulfil the Authenticator Assurance Level, implying that the session must (e.g.) authenticate the second factor.
1393pub async fn to_session(configuration: &configuration::Configuration, x_session_token: Option<&str>, cookie: Option<&str>, tokenize_as: Option<&str>) -> Result<models::Session, Error<ToSessionError>> {
1394    // add a prefix to parameters to efficiently prevent name collisions
1395    let p_header_x_session_token = x_session_token;
1396    let p_header_cookie = cookie;
1397    let p_query_tokenize_as = tokenize_as;
1398
1399    let uri_str = format!("{}/sessions/whoami", configuration.base_path);
1400    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1401
1402    if let Some(ref param_value) = p_query_tokenize_as {
1403        req_builder = req_builder.query(&[("tokenize_as", &param_value.to_string())]);
1404    }
1405    if let Some(ref user_agent) = configuration.user_agent {
1406        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1407    }
1408    if let Some(param_value) = p_header_x_session_token {
1409        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
1410    }
1411    if let Some(param_value) = p_header_cookie {
1412        req_builder = req_builder.header("Cookie", param_value.to_string());
1413    }
1414
1415    let req = req_builder.build()?;
1416    let resp = configuration.client.execute(req).await?;
1417
1418    let status = resp.status();
1419    let content_type = resp
1420        .headers()
1421        .get("content-type")
1422        .and_then(|v| v.to_str().ok())
1423        .unwrap_or("application/octet-stream");
1424    let content_type = super::ContentType::from(content_type);
1425
1426    if !status.is_client_error() && !status.is_server_error() {
1427        let content = resp.text().await?;
1428        match content_type {
1429            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1430            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Session`"))),
1431            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::Session`")))),
1432        }
1433    } else {
1434        let content = resp.text().await?;
1435        let entity: Option<ToSessionError> = serde_json::from_str(&content).ok();
1436        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1437    }
1438}
1439
1440/// Use this endpoint to submit a token from a FedCM provider through `navigator.credentials.get` and log the user in. The parameters from `navigator.credentials.get` must have come from `GET self-service/fed-cm/parameters`.
1441pub async fn update_fedcm_flow(configuration: &configuration::Configuration, update_fedcm_flow_body: models::UpdateFedcmFlowBody) -> Result<models::SuccessfulNativeLogin, Error<UpdateFedcmFlowError>> {
1442    // add a prefix to parameters to efficiently prevent name collisions
1443    let p_body_update_fedcm_flow_body = update_fedcm_flow_body;
1444
1445    let uri_str = format!("{}/self-service/fed-cm/token", configuration.base_path);
1446    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1447
1448    if let Some(ref user_agent) = configuration.user_agent {
1449        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1450    }
1451    req_builder = req_builder.json(&p_body_update_fedcm_flow_body);
1452
1453    let req = req_builder.build()?;
1454    let resp = configuration.client.execute(req).await?;
1455
1456    let status = resp.status();
1457    let content_type = resp
1458        .headers()
1459        .get("content-type")
1460        .and_then(|v| v.to_str().ok())
1461        .unwrap_or("application/octet-stream");
1462    let content_type = super::ContentType::from(content_type);
1463
1464    if !status.is_client_error() && !status.is_server_error() {
1465        let content = resp.text().await?;
1466        match content_type {
1467            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1468            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SuccessfulNativeLogin`"))),
1469            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::SuccessfulNativeLogin`")))),
1470        }
1471    } else {
1472        let content = resp.text().await?;
1473        let entity: Option<UpdateFedcmFlowError> = serde_json::from_str(&content).ok();
1474        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1475    }
1476}
1477
1478/// Use this endpoint to complete a login flow. This endpoint behaves differently for API and browser flows.  API flows expect `application/json` to be sent in the body and responds with HTTP 200 and a application/json body with the session token on success; HTTP 410 if the original flow expired with the appropriate error messages set and optionally a `use_flow_id` parameter in the body; HTTP 400 on form validation errors.  Browser flows expect a Content-Type of `application/x-www-form-urlencoded` or `application/json` to be sent in the body and respond with a HTTP 303 redirect to the post/after login URL or the `return_to` value if it was set and if the login succeeded; a HTTP 303 redirect to the login UI URL with the flow ID containing the validation errors otherwise.  Browser flows with an accept header of `application/json` will not redirect but instead respond with HTTP 200 and a application/json body with the signed in identity and a `Set-Cookie` header on success; HTTP 303 redirect to a fresh login flow if the original flow expired with the appropriate error messages set; HTTP 400 on form validation errors.  If this endpoint is called with `Accept: application/json` in the header, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `session_already_available`: The user is already signed in. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `security_identity_mismatch`: The requested `?return_to` address is not allowed to be used. Adjust this in the configuration! `browser_location_change_required`: Usually sent when an AJAX request indicates that the browser needs to open a specific URL. Most likely used in Social Sign In flows.  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
1479pub async fn update_login_flow(configuration: &configuration::Configuration, flow: &str, update_login_flow_body: models::UpdateLoginFlowBody, x_session_token: Option<&str>, cookie: Option<&str>) -> Result<models::SuccessfulNativeLogin, Error<UpdateLoginFlowError>> {
1480    // add a prefix to parameters to efficiently prevent name collisions
1481    let p_query_flow = flow;
1482    let p_body_update_login_flow_body = update_login_flow_body;
1483    let p_header_x_session_token = x_session_token;
1484    let p_header_cookie = cookie;
1485
1486    let uri_str = format!("{}/self-service/login", configuration.base_path);
1487    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1488
1489    req_builder = req_builder.query(&[("flow", &p_query_flow.to_string())]);
1490    if let Some(ref user_agent) = configuration.user_agent {
1491        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1492    }
1493    if let Some(param_value) = p_header_x_session_token {
1494        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
1495    }
1496    if let Some(param_value) = p_header_cookie {
1497        req_builder = req_builder.header("Cookie", param_value.to_string());
1498    }
1499    req_builder = req_builder.json(&p_body_update_login_flow_body);
1500
1501    let req = req_builder.build()?;
1502    let resp = configuration.client.execute(req).await?;
1503
1504    let status = resp.status();
1505    let content_type = resp
1506        .headers()
1507        .get("content-type")
1508        .and_then(|v| v.to_str().ok())
1509        .unwrap_or("application/octet-stream");
1510    let content_type = super::ContentType::from(content_type);
1511
1512    if !status.is_client_error() && !status.is_server_error() {
1513        let content = resp.text().await?;
1514        match content_type {
1515            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1516            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SuccessfulNativeLogin`"))),
1517            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::SuccessfulNativeLogin`")))),
1518        }
1519    } else {
1520        let content = resp.text().await?;
1521        let entity: Option<UpdateLoginFlowError> = serde_json::from_str(&content).ok();
1522        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1523    }
1524}
1525
1526/// This endpoint logs out an identity in a self-service manner.  If the `Accept` HTTP header is not set to `application/json`, the browser will be redirected (HTTP 303 See Other) to the `return_to` parameter of the initial request or fall back to `urls.default_return_to`.  If the `Accept` HTTP header is set to `application/json`, a 204 No Content response will be sent on successful logout instead.  This endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...). For API clients you can call the `/self-service/logout/api` URL directly with the Ory Session Token.  More information can be found at [Ory Kratos User Logout Documentation](https://www.ory.com/docs/next/kratos/self-service/flows/user-logout).
1527pub async fn update_logout_flow(configuration: &configuration::Configuration, token: Option<&str>, return_to: Option<&str>, cookie: Option<&str>) -> Result<(), Error<UpdateLogoutFlowError>> {
1528    // add a prefix to parameters to efficiently prevent name collisions
1529    let p_query_token = token;
1530    let p_query_return_to = return_to;
1531    let p_header_cookie = cookie;
1532
1533    let uri_str = format!("{}/self-service/logout", configuration.base_path);
1534    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1535
1536    if let Some(ref param_value) = p_query_token {
1537        req_builder = req_builder.query(&[("token", &param_value.to_string())]);
1538    }
1539    if let Some(ref param_value) = p_query_return_to {
1540        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
1541    }
1542    if let Some(ref user_agent) = configuration.user_agent {
1543        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1544    }
1545    if let Some(param_value) = p_header_cookie {
1546        req_builder = req_builder.header("Cookie", param_value.to_string());
1547    }
1548
1549    let req = req_builder.build()?;
1550    let resp = configuration.client.execute(req).await?;
1551
1552    let status = resp.status();
1553
1554    if !status.is_client_error() && !status.is_server_error() {
1555        Ok(())
1556    } else {
1557        let content = resp.text().await?;
1558        let entity: Option<UpdateLogoutFlowError> = serde_json::from_str(&content).ok();
1559        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1560    }
1561}
1562
1563/// Use this endpoint to update a recovery flow. This endpoint behaves differently for API and browser flows and has several states:  `choose_method` expects `flow` (in the URL query) and `email` (in the body) to be sent and works with API- and Browser-initiated flows. For API clients and Browser clients with HTTP Header `Accept: application/json` it either returns a HTTP 200 OK when the form is valid and HTTP 400 OK when the form is invalid. and a HTTP 303 See Other redirect with a fresh recovery flow if the flow was otherwise invalid (e.g. expired). For Browser clients without HTTP Header `Accept` or with `Accept: text/_*` it returns a HTTP 303 See Other redirect to the Recovery UI URL with the Recovery Flow ID appended. `sent_email` is the success state after `choose_method` for the `link` method and allows the user to request another recovery email. It works for both API and Browser-initiated flows and returns the same responses as the flow in `choose_method` state. `passed_challenge` expects a `token` to be sent in the URL query and given the nature of the flow (\"sending a recovery link\") does not have any API capabilities. The server responds with a HTTP 303 See Other redirect either to the Settings UI URL (if the link was valid) and instructs the user to update their password, or a redirect to the Recover UI URL with a new Recovery Flow ID which contains an error message that the recovery link was invalid.  More information can be found at [Ory Kratos Account Recovery Documentation](../self-service/flows/account-recovery).
1564pub async fn update_recovery_flow(configuration: &configuration::Configuration, flow: &str, update_recovery_flow_body: models::UpdateRecoveryFlowBody, token: Option<&str>, cookie: Option<&str>) -> Result<models::RecoveryFlow, Error<UpdateRecoveryFlowError>> {
1565    // add a prefix to parameters to efficiently prevent name collisions
1566    let p_query_flow = flow;
1567    let p_body_update_recovery_flow_body = update_recovery_flow_body;
1568    let p_query_token = token;
1569    let p_header_cookie = cookie;
1570
1571    let uri_str = format!("{}/self-service/recovery", configuration.base_path);
1572    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1573
1574    req_builder = req_builder.query(&[("flow", &p_query_flow.to_string())]);
1575    if let Some(ref param_value) = p_query_token {
1576        req_builder = req_builder.query(&[("token", &param_value.to_string())]);
1577    }
1578    if let Some(ref user_agent) = configuration.user_agent {
1579        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1580    }
1581    if let Some(param_value) = p_header_cookie {
1582        req_builder = req_builder.header("Cookie", param_value.to_string());
1583    }
1584    req_builder = req_builder.json(&p_body_update_recovery_flow_body);
1585
1586    let req = req_builder.build()?;
1587    let resp = configuration.client.execute(req).await?;
1588
1589    let status = resp.status();
1590    let content_type = resp
1591        .headers()
1592        .get("content-type")
1593        .and_then(|v| v.to_str().ok())
1594        .unwrap_or("application/octet-stream");
1595    let content_type = super::ContentType::from(content_type);
1596
1597    if !status.is_client_error() && !status.is_server_error() {
1598        let content = resp.text().await?;
1599        match content_type {
1600            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1601            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryFlow`"))),
1602            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::RecoveryFlow`")))),
1603        }
1604    } else {
1605        let content = resp.text().await?;
1606        let entity: Option<UpdateRecoveryFlowError> = serde_json::from_str(&content).ok();
1607        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1608    }
1609}
1610
1611/// Use this endpoint to complete a registration flow by sending an identity's traits and password. This endpoint behaves differently for API and browser flows.  API flows expect `application/json` to be sent in the body and respond with HTTP 200 and a application/json body with the created identity success - if the session hook is configured the `session` and `session_token` will also be included; HTTP 410 if the original flow expired with the appropriate error messages set and optionally a `use_flow_id` parameter in the body; HTTP 400 on form validation errors.  Browser flows expect a Content-Type of `application/x-www-form-urlencoded` or `application/json` to be sent in the body and respond with a HTTP 303 redirect to the post/after registration URL or the `return_to` value if it was set and if the registration succeeded; a HTTP 303 redirect to the registration UI URL with the flow ID containing the validation errors otherwise.  Browser flows with an accept header of `application/json` will not redirect but instead respond with HTTP 200 and a application/json body with the signed in identity and a `Set-Cookie` header on success; HTTP 303 redirect to a fresh login flow if the original flow expired with the appropriate error messages set; HTTP 400 on form validation errors.  If this endpoint is called with `Accept: application/json` in the header, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `session_already_available`: The user is already signed in. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `security_identity_mismatch`: The requested `?return_to` address is not allowed to be used. Adjust this in the configuration! `browser_location_change_required`: Usually sent when an AJAX request indicates that the browser needs to open a specific URL. Most likely used in Social Sign In flows.  More information can be found at [Ory Kratos User Login](https://www.ory.com/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.com/docs/kratos/self-service/flows/user-registration).
1612pub async fn update_registration_flow(configuration: &configuration::Configuration, flow: &str, update_registration_flow_body: models::UpdateRegistrationFlowBody, cookie: Option<&str>) -> Result<models::SuccessfulNativeRegistration, Error<UpdateRegistrationFlowError>> {
1613    // add a prefix to parameters to efficiently prevent name collisions
1614    let p_query_flow = flow;
1615    let p_body_update_registration_flow_body = update_registration_flow_body;
1616    let p_header_cookie = cookie;
1617
1618    let uri_str = format!("{}/self-service/registration", configuration.base_path);
1619    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1620
1621    req_builder = req_builder.query(&[("flow", &p_query_flow.to_string())]);
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(param_value) = p_header_cookie {
1626        req_builder = req_builder.header("Cookie", param_value.to_string());
1627    }
1628    req_builder = req_builder.json(&p_body_update_registration_flow_body);
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::SuccessfulNativeRegistration`"))),
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::SuccessfulNativeRegistration`")))),
1647        }
1648    } else {
1649        let content = resp.text().await?;
1650        let entity: Option<UpdateRegistrationFlowError> = serde_json::from_str(&content).ok();
1651        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1652    }
1653}
1654
1655/// Use this endpoint to complete a settings flow by sending an identity's updated password. This endpoint behaves differently for API and browser flows.  API-initiated flows expect `application/json` to be sent in the body and respond with HTTP 200 and an application/json body with the session token on success; HTTP 303 redirect to a fresh settings flow if the original flow expired with the appropriate error messages set; HTTP 400 on form validation errors. HTTP 401 when the endpoint is called without a valid session token. HTTP 403 when `selfservice.flows.settings.privileged_session_max_age` was reached or the session's AAL is too low. Implies that the user needs to re-authenticate.  Browser flows without HTTP Header `Accept` or with `Accept: text/_*` respond with a HTTP 303 redirect to the post/after settings URL or the `return_to` value if it was set and if the flow succeeded; a HTTP 303 redirect to the Settings UI URL with the flow ID containing the validation errors otherwise. a HTTP 303 redirect to the login endpoint when `selfservice.flows.settings.privileged_session_max_age` was reached or the session's AAL is too low.  Browser flows with HTTP Header `Accept: application/json` respond with HTTP 200 and a application/json body with the signed in identity and a `Set-Cookie` header on success; HTTP 303 redirect to a fresh login flow if the original flow expired with the appropriate error messages set; HTTP 401 when the endpoint is called without a valid session cookie. HTTP 403 when the page is accessed without a session cookie or the session's AAL is too low. HTTP 400 on form validation errors.  Depending on your configuration this endpoint might return a 403 error if the session has a lower Authenticator Assurance Level (AAL) than is possible for the identity. This can happen if the identity has password + webauthn credentials (which would result in AAL2) but the session has only AAL1. If this error occurs, ask the user to sign in with the second factor (happens automatically for server-side browser flows) or change the configuration.  If this endpoint is called with a `Accept: application/json` HTTP header, the response contains the flow without a redirect. In the case of an error, the `error.id` of the JSON response body can be one of:  `session_refresh_required`: The identity requested to change something that needs a privileged session. Redirect the identity to the login init endpoint with query parameters `?refresh=true&return_to=<the-current-browser-url>`, or initiate a refresh login flow otherwise. `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. `session_inactive`: No Ory Session was found - sign in a user first. `security_identity_mismatch`: The flow was interrupted with `session_refresh_required` but apparently some other identity logged in instead. `security_identity_mismatch`: The requested `?return_to` address is not allowed to be used. Adjust this in the configuration! `browser_location_change_required`: Usually sent when an AJAX request indicates that the browser needs to open a specific URL. Most likely used in Social Sign In flows.  More information can be found at [Ory Kratos User Settings & Profile Management Documentation](../self-service/flows/user-settings).
1656pub async fn update_settings_flow(configuration: &configuration::Configuration, flow: &str, update_settings_flow_body: models::UpdateSettingsFlowBody, x_session_token: Option<&str>, cookie: Option<&str>) -> Result<models::SettingsFlow, Error<UpdateSettingsFlowError>> {
1657    // add a prefix to parameters to efficiently prevent name collisions
1658    let p_query_flow = flow;
1659    let p_body_update_settings_flow_body = update_settings_flow_body;
1660    let p_header_x_session_token = x_session_token;
1661    let p_header_cookie = cookie;
1662
1663    let uri_str = format!("{}/self-service/settings", configuration.base_path);
1664    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1665
1666    req_builder = req_builder.query(&[("flow", &p_query_flow.to_string())]);
1667    if let Some(ref user_agent) = configuration.user_agent {
1668        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1669    }
1670    if let Some(param_value) = p_header_x_session_token {
1671        req_builder = req_builder.header("X-Session-Token", param_value.to_string());
1672    }
1673    if let Some(param_value) = p_header_cookie {
1674        req_builder = req_builder.header("Cookie", param_value.to_string());
1675    }
1676    req_builder = req_builder.json(&p_body_update_settings_flow_body);
1677
1678    let req = req_builder.build()?;
1679    let resp = configuration.client.execute(req).await?;
1680
1681    let status = resp.status();
1682    let content_type = resp
1683        .headers()
1684        .get("content-type")
1685        .and_then(|v| v.to_str().ok())
1686        .unwrap_or("application/octet-stream");
1687    let content_type = super::ContentType::from(content_type);
1688
1689    if !status.is_client_error() && !status.is_server_error() {
1690        let content = resp.text().await?;
1691        match content_type {
1692            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1693            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SettingsFlow`"))),
1694            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::SettingsFlow`")))),
1695        }
1696    } else {
1697        let content = resp.text().await?;
1698        let entity: Option<UpdateSettingsFlowError> = serde_json::from_str(&content).ok();
1699        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1700    }
1701}
1702
1703/// Use this endpoint to complete a verification flow. This endpoint behaves differently for API and browser flows and has several states:  `choose_method` expects `flow` (in the URL query) and `email` (in the body) to be sent and works with API- and Browser-initiated flows. For API clients and Browser clients with HTTP Header `Accept: application/json` it either returns a HTTP 200 OK when the form is valid and HTTP 400 OK when the form is invalid and a HTTP 303 See Other redirect with a fresh verification flow if the flow was otherwise invalid (e.g. expired). For Browser clients without HTTP Header `Accept` or with `Accept: text/_*` it returns a HTTP 303 See Other redirect to the Verification UI URL with the Verification Flow ID appended. `sent_email` is the success state after `choose_method` when using the `link` method and allows the user to request another verification email. It works for both API and Browser-initiated flows and returns the same responses as the flow in `choose_method` state. `passed_challenge` expects a `token` to be sent in the URL query and given the nature of the flow (\"sending a verification link\") does not have any API capabilities. The server responds with a HTTP 303 See Other redirect either to the Settings UI URL (if the link was valid) and instructs the user to update their password, or a redirect to the Verification UI URL with a new Verification Flow ID which contains an error message that the verification link was invalid.  More information can be found at [Ory Kratos Email and Phone Verification Documentation](https://www.ory.com/docs/kratos/self-service/flows/verify-email-account-activation).
1704pub async fn update_verification_flow(configuration: &configuration::Configuration, flow: &str, update_verification_flow_body: models::UpdateVerificationFlowBody, token: Option<&str>, cookie: Option<&str>) -> Result<models::VerificationFlow, Error<UpdateVerificationFlowError>> {
1705    // add a prefix to parameters to efficiently prevent name collisions
1706    let p_query_flow = flow;
1707    let p_body_update_verification_flow_body = update_verification_flow_body;
1708    let p_query_token = token;
1709    let p_header_cookie = cookie;
1710
1711    let uri_str = format!("{}/self-service/verification", configuration.base_path);
1712    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1713
1714    req_builder = req_builder.query(&[("flow", &p_query_flow.to_string())]);
1715    if let Some(ref param_value) = p_query_token {
1716        req_builder = req_builder.query(&[("token", &param_value.to_string())]);
1717    }
1718    if let Some(ref user_agent) = configuration.user_agent {
1719        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1720    }
1721    if let Some(param_value) = p_header_cookie {
1722        req_builder = req_builder.header("Cookie", param_value.to_string());
1723    }
1724    req_builder = req_builder.json(&p_body_update_verification_flow_body);
1725
1726    let req = req_builder.build()?;
1727    let resp = configuration.client.execute(req).await?;
1728
1729    let status = resp.status();
1730    let content_type = resp
1731        .headers()
1732        .get("content-type")
1733        .and_then(|v| v.to_str().ok())
1734        .unwrap_or("application/octet-stream");
1735    let content_type = super::ContentType::from(content_type);
1736
1737    if !status.is_client_error() && !status.is_server_error() {
1738        let content = resp.text().await?;
1739        match content_type {
1740            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1741            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerificationFlow`"))),
1742            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::VerificationFlow`")))),
1743        }
1744    } else {
1745        let content = resp.text().await?;
1746        let entity: Option<UpdateVerificationFlowError> = serde_json::from_str(&content).ok();
1747        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1748    }
1749}
1750