Skip to main content

ory_client/apis/
identity_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.43
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 [`batch_patch_identities`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum BatchPatchIdentitiesError {
22    Status400(models::ErrorGeneric),
23    Status409(models::ErrorGeneric),
24    DefaultResponse(models::ErrorGeneric),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`create_identity`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreateIdentityError {
32    Status400(models::ErrorGeneric),
33    Status409(models::ErrorGeneric),
34    DefaultResponse(models::ErrorGeneric),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`create_recovery_code_for_identity`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum CreateRecoveryCodeForIdentityError {
42    Status400(models::ErrorGeneric),
43    Status404(models::ErrorGeneric),
44    DefaultResponse(models::ErrorGeneric),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`create_recovery_link_for_identity`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum CreateRecoveryLinkForIdentityError {
52    Status400(models::ErrorGeneric),
53    Status404(models::ErrorGeneric),
54    DefaultResponse(models::ErrorGeneric),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`create_test_login_flow`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum CreateTestLoginFlowError {
62    Status400(models::ErrorGeneric),
63    Status404(models::ErrorGeneric),
64    DefaultResponse(models::ErrorGeneric),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`delete_identity`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum DeleteIdentityError {
72    Status404(models::ErrorGeneric),
73    DefaultResponse(models::ErrorGeneric),
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`delete_identity_credentials`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum DeleteIdentityCredentialsError {
81    Status404(models::ErrorGeneric),
82    DefaultResponse(models::ErrorGeneric),
83    UnknownValue(serde_json::Value),
84}
85
86/// struct for typed errors of method [`delete_identity_sessions`]
87#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum DeleteIdentitySessionsError {
90    Status400(models::ErrorGeneric),
91    Status401(models::ErrorGeneric),
92    Status404(models::ErrorGeneric),
93    DefaultResponse(models::ErrorGeneric),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`disable_session`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum DisableSessionError {
101    Status400(models::ErrorGeneric),
102    Status401(models::ErrorGeneric),
103    DefaultResponse(models::ErrorGeneric),
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`extend_session`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum ExtendSessionError {
111    Status400(models::ErrorGeneric),
112    Status404(models::ErrorGeneric),
113    DefaultResponse(models::ErrorGeneric),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`get_identity`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum GetIdentityError {
121    Status404(models::ErrorGeneric),
122    DefaultResponse(models::ErrorGeneric),
123    UnknownValue(serde_json::Value),
124}
125
126/// struct for typed errors of method [`get_identity_by_external_id`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum GetIdentityByExternalIdError {
130    Status404(models::ErrorGeneric),
131    DefaultResponse(models::ErrorGeneric),
132    UnknownValue(serde_json::Value),
133}
134
135/// struct for typed errors of method [`get_identity_schema`]
136#[derive(Debug, Clone, Serialize, Deserialize)]
137#[serde(untagged)]
138pub enum GetIdentitySchemaError {
139    Status404(models::ErrorGeneric),
140    DefaultResponse(models::ErrorGeneric),
141    UnknownValue(serde_json::Value),
142}
143
144/// struct for typed errors of method [`get_session`]
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum GetSessionError {
148    Status400(models::ErrorGeneric),
149    DefaultResponse(models::ErrorGeneric),
150    UnknownValue(serde_json::Value),
151}
152
153/// struct for typed errors of method [`list_identities`]
154#[derive(Debug, Clone, Serialize, Deserialize)]
155#[serde(untagged)]
156pub enum ListIdentitiesError {
157    DefaultResponse(models::ErrorGeneric),
158    UnknownValue(serde_json::Value),
159}
160
161/// struct for typed errors of method [`list_identity_schemas`]
162#[derive(Debug, Clone, Serialize, Deserialize)]
163#[serde(untagged)]
164pub enum ListIdentitySchemasError {
165    DefaultResponse(models::ErrorGeneric),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`list_identity_sessions`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum ListIdentitySessionsError {
173    Status400(models::ErrorGeneric),
174    Status404(models::ErrorGeneric),
175    DefaultResponse(models::ErrorGeneric),
176    UnknownValue(serde_json::Value),
177}
178
179/// struct for typed errors of method [`list_sessions`]
180#[derive(Debug, Clone, Serialize, Deserialize)]
181#[serde(untagged)]
182pub enum ListSessionsError {
183    Status400(models::ErrorGeneric),
184    DefaultResponse(models::ErrorGeneric),
185    UnknownValue(serde_json::Value),
186}
187
188/// struct for typed errors of method [`manage_sessions`]
189#[derive(Debug, Clone, Serialize, Deserialize)]
190#[serde(untagged)]
191pub enum ManageSessionsError {
192    Status400(models::ErrorGeneric),
193    Status401(models::ErrorGeneric),
194    DefaultResponse(models::ErrorGeneric),
195    UnknownValue(serde_json::Value),
196}
197
198/// struct for typed errors of method [`patch_identity`]
199#[derive(Debug, Clone, Serialize, Deserialize)]
200#[serde(untagged)]
201pub enum PatchIdentityError {
202    Status400(models::ErrorGeneric),
203    Status404(models::ErrorGeneric),
204    Status409(models::ErrorGeneric),
205    DefaultResponse(models::ErrorGeneric),
206    UnknownValue(serde_json::Value),
207}
208
209/// struct for typed errors of method [`update_identity`]
210#[derive(Debug, Clone, Serialize, Deserialize)]
211#[serde(untagged)]
212pub enum UpdateIdentityError {
213    Status400(models::ErrorGeneric),
214    Status404(models::ErrorGeneric),
215    Status409(models::ErrorGeneric),
216    DefaultResponse(models::ErrorGeneric),
217    UnknownValue(serde_json::Value),
218}
219
220
221/// Creates multiple [identities](https://www.ory.com/docs/kratos/concepts/identity-user-model).  You can also use this endpoint to [import credentials](https://www.ory.com/docs/kratos/manage-identities/import-user-accounts-identities), including passwords, social sign-in settings, and multi-factor authentication methods.  If the patch includes hashed passwords you can import up to 1,000 identities per request.  If the patch includes at least one plaintext password you can import up to 200 identities per request.  Avoid importing large batches with plaintext passwords. They can cause timeouts as the passwords need to be hashed before they are stored.  If at least one identity is imported successfully, the response status is 200 OK. If all imports fail, the response is one of the following 4xx errors: 400 Bad Request: The request payload is invalid or improperly formatted. 409 Conflict: Duplicate identities or conflicting data were detected.  If you get a 504 Gateway Timeout: Reduce the batch size Avoid duplicate identities Pre-hash passwords with BCrypt  If the issue persists, contact support.
222pub async fn batch_patch_identities(configuration: &configuration::Configuration, patch_identities_body: Option<models::PatchIdentitiesBody>) -> Result<models::BatchPatchIdentitiesResponse, Error<BatchPatchIdentitiesError>> {
223    // add a prefix to parameters to efficiently prevent name collisions
224    let p_body_patch_identities_body = patch_identities_body;
225
226    let uri_str = format!("{}/admin/identities", configuration.base_path);
227    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
228
229    if let Some(ref user_agent) = configuration.user_agent {
230        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
231    }
232    if let Some(ref token) = configuration.bearer_access_token {
233        req_builder = req_builder.bearer_auth(token.to_owned());
234    };
235    req_builder = req_builder.json(&p_body_patch_identities_body);
236
237    let req = req_builder.build()?;
238    let resp = configuration.client.execute(req).await?;
239
240    let status = resp.status();
241    let content_type = resp
242        .headers()
243        .get("content-type")
244        .and_then(|v| v.to_str().ok())
245        .unwrap_or("application/octet-stream");
246    let content_type = super::ContentType::from(content_type);
247
248    if !status.is_client_error() && !status.is_server_error() {
249        let content = resp.text().await?;
250        match content_type {
251            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
252            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchPatchIdentitiesResponse`"))),
253            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::BatchPatchIdentitiesResponse`")))),
254        }
255    } else {
256        let content = resp.text().await?;
257        let entity: Option<BatchPatchIdentitiesError> = serde_json::from_str(&content).ok();
258        Err(Error::ResponseError(ResponseContent { status, content, entity }))
259    }
260}
261
262/// Create an [identity](https://www.ory.com/docs/kratos/concepts/identity-user-model).  This endpoint can also be used to [import credentials](https://www.ory.com/docs/kratos/manage-identities/import-user-accounts-identities) for instance passwords, social sign in configurations, or multifactor methods.
263pub async fn create_identity(configuration: &configuration::Configuration, create_identity_body: Option<models::CreateIdentityBody>) -> Result<models::Identity, Error<CreateIdentityError>> {
264    // add a prefix to parameters to efficiently prevent name collisions
265    let p_body_create_identity_body = create_identity_body;
266
267    let uri_str = format!("{}/admin/identities", configuration.base_path);
268    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
269
270    if let Some(ref user_agent) = configuration.user_agent {
271        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
272    }
273    if let Some(ref token) = configuration.bearer_access_token {
274        req_builder = req_builder.bearer_auth(token.to_owned());
275    };
276    req_builder = req_builder.json(&p_body_create_identity_body);
277
278    let req = req_builder.build()?;
279    let resp = configuration.client.execute(req).await?;
280
281    let status = resp.status();
282    let content_type = resp
283        .headers()
284        .get("content-type")
285        .and_then(|v| v.to_str().ok())
286        .unwrap_or("application/octet-stream");
287    let content_type = super::ContentType::from(content_type);
288
289    if !status.is_client_error() && !status.is_server_error() {
290        let content = resp.text().await?;
291        match content_type {
292            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
293            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
294            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Identity`")))),
295        }
296    } else {
297        let content = resp.text().await?;
298        let entity: Option<CreateIdentityError> = serde_json::from_str(&content).ok();
299        Err(Error::ResponseError(ResponseContent { status, content, entity }))
300    }
301}
302
303/// This endpoint creates a recovery code which should be given to the user in order for them to recover (or activate) their account.
304pub async fn create_recovery_code_for_identity(configuration: &configuration::Configuration, create_recovery_code_for_identity_body: Option<models::CreateRecoveryCodeForIdentityBody>) -> Result<models::RecoveryCodeForIdentity, Error<CreateRecoveryCodeForIdentityError>> {
305    // add a prefix to parameters to efficiently prevent name collisions
306    let p_body_create_recovery_code_for_identity_body = create_recovery_code_for_identity_body;
307
308    let uri_str = format!("{}/admin/recovery/code", configuration.base_path);
309    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
310
311    if let Some(ref user_agent) = configuration.user_agent {
312        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
313    }
314    if let Some(ref token) = configuration.bearer_access_token {
315        req_builder = req_builder.bearer_auth(token.to_owned());
316    };
317    req_builder = req_builder.json(&p_body_create_recovery_code_for_identity_body);
318
319    let req = req_builder.build()?;
320    let resp = configuration.client.execute(req).await?;
321
322    let status = resp.status();
323    let content_type = resp
324        .headers()
325        .get("content-type")
326        .and_then(|v| v.to_str().ok())
327        .unwrap_or("application/octet-stream");
328    let content_type = super::ContentType::from(content_type);
329
330    if !status.is_client_error() && !status.is_server_error() {
331        let content = resp.text().await?;
332        match content_type {
333            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
334            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryCodeForIdentity`"))),
335            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::RecoveryCodeForIdentity`")))),
336        }
337    } else {
338        let content = resp.text().await?;
339        let entity: Option<CreateRecoveryCodeForIdentityError> = serde_json::from_str(&content).ok();
340        Err(Error::ResponseError(ResponseContent { status, content, entity }))
341    }
342}
343
344/// This endpoint creates a recovery link which should be given to the user in order for them to recover (or activate) their account.
345pub async fn create_recovery_link_for_identity(configuration: &configuration::Configuration, return_to: Option<&str>, create_recovery_link_for_identity_body: Option<models::CreateRecoveryLinkForIdentityBody>) -> Result<models::RecoveryLinkForIdentity, Error<CreateRecoveryLinkForIdentityError>> {
346    // add a prefix to parameters to efficiently prevent name collisions
347    let p_query_return_to = return_to;
348    let p_body_create_recovery_link_for_identity_body = create_recovery_link_for_identity_body;
349
350    let uri_str = format!("{}/admin/recovery/link", configuration.base_path);
351    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
352
353    if let Some(ref param_value) = p_query_return_to {
354        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
355    }
356    if let Some(ref user_agent) = configuration.user_agent {
357        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
358    }
359    if let Some(ref token) = configuration.bearer_access_token {
360        req_builder = req_builder.bearer_auth(token.to_owned());
361    };
362    req_builder = req_builder.json(&p_body_create_recovery_link_for_identity_body);
363
364    let req = req_builder.build()?;
365    let resp = configuration.client.execute(req).await?;
366
367    let status = resp.status();
368    let content_type = resp
369        .headers()
370        .get("content-type")
371        .and_then(|v| v.to_str().ok())
372        .unwrap_or("application/octet-stream");
373    let content_type = super::ContentType::from(content_type);
374
375    if !status.is_client_error() && !status.is_server_error() {
376        let content = resp.text().await?;
377        match content_type {
378            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
379            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryLinkForIdentity`"))),
380            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::RecoveryLinkForIdentity`")))),
381        }
382    } else {
383        let content = resp.text().await?;
384        let entity: Option<CreateRecoveryLinkForIdentityError> = serde_json::from_str(&content).ok();
385        Err(Error::ResponseError(ResponseContent { status, content, entity }))
386    }
387}
388
389/// Creates a dry-run OIDC test login flow pre-scoped to one provider. The returned flow carries a single-submit UI and a CSRF bearer token. No identity is persisted and no session is issued when the flow completes; the captured debug data is returned in the flow's test_context.
390pub async fn create_test_login_flow(configuration: &configuration::Configuration, create_test_login_flow_body: models::CreateTestLoginFlowBody) -> Result<models::LoginFlow, Error<CreateTestLoginFlowError>> {
391    // add a prefix to parameters to efficiently prevent name collisions
392    let p_body_create_test_login_flow_body = create_test_login_flow_body;
393
394    let uri_str = format!("{}/admin/test-login-flows", configuration.base_path);
395    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
396
397    if let Some(ref user_agent) = configuration.user_agent {
398        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
399    }
400    if let Some(ref token) = configuration.bearer_access_token {
401        req_builder = req_builder.bearer_auth(token.to_owned());
402    };
403    req_builder = req_builder.json(&p_body_create_test_login_flow_body);
404
405    let req = req_builder.build()?;
406    let resp = configuration.client.execute(req).await?;
407
408    let status = resp.status();
409    let content_type = resp
410        .headers()
411        .get("content-type")
412        .and_then(|v| v.to_str().ok())
413        .unwrap_or("application/octet-stream");
414    let content_type = super::ContentType::from(content_type);
415
416    if !status.is_client_error() && !status.is_server_error() {
417        let content = resp.text().await?;
418        match content_type {
419            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
420            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginFlow`"))),
421            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`")))),
422        }
423    } else {
424        let content = resp.text().await?;
425        let entity: Option<CreateTestLoginFlowError> = serde_json::from_str(&content).ok();
426        Err(Error::ResponseError(ResponseContent { status, content, entity }))
427    }
428}
429
430/// Calling this endpoint irrecoverably and permanently deletes the [identity](https://www.ory.com/docs/kratos/concepts/identity-user-model) given its ID. This action can not be undone. This endpoint returns 204 when the identity was deleted or 404 if the identity was not found.
431pub async fn delete_identity(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentityError>> {
432    // add a prefix to parameters to efficiently prevent name collisions
433    let p_path_id = id;
434
435    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
436    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
437
438    if let Some(ref user_agent) = configuration.user_agent {
439        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
440    }
441    if let Some(ref token) = configuration.bearer_access_token {
442        req_builder = req_builder.bearer_auth(token.to_owned());
443    };
444
445    let req = req_builder.build()?;
446    let resp = configuration.client.execute(req).await?;
447
448    let status = resp.status();
449
450    if !status.is_client_error() && !status.is_server_error() {
451        Ok(())
452    } else {
453        let content = resp.text().await?;
454        let entity: Option<DeleteIdentityError> = serde_json::from_str(&content).ok();
455        Err(Error::ResponseError(ResponseContent { status, content, entity }))
456    }
457}
458
459/// Delete an [identity](https://www.ory.com/docs/kratos/concepts/identity-user-model) credential by its type. You cannot delete passkeys or code auth credentials through this API.
460pub async fn delete_identity_credentials(configuration: &configuration::Configuration, id: &str, r#type: &str, identifier: Option<&str>) -> Result<(), Error<DeleteIdentityCredentialsError>> {
461    // add a prefix to parameters to efficiently prevent name collisions
462    let p_path_id = id;
463    let p_path_type = r#type;
464    let p_query_identifier = identifier;
465
466    let uri_str = format!("{}/admin/identities/{id}/credentials/{type}", configuration.base_path, id=crate::apis::urlencode(p_path_id), type=crate::apis::urlencode(p_path_type));
467    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
468
469    if let Some(ref param_value) = p_query_identifier {
470        req_builder = req_builder.query(&[("identifier", &param_value.to_string())]);
471    }
472    if let Some(ref user_agent) = configuration.user_agent {
473        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
474    }
475    if let Some(ref token) = configuration.bearer_access_token {
476        req_builder = req_builder.bearer_auth(token.to_owned());
477    };
478
479    let req = req_builder.build()?;
480    let resp = configuration.client.execute(req).await?;
481
482    let status = resp.status();
483
484    if !status.is_client_error() && !status.is_server_error() {
485        Ok(())
486    } else {
487        let content = resp.text().await?;
488        let entity: Option<DeleteIdentityCredentialsError> = serde_json::from_str(&content).ok();
489        Err(Error::ResponseError(ResponseContent { status, content, entity }))
490    }
491}
492
493/// Calling this endpoint irrecoverably and permanently deletes and invalidates all sessions that belong to the given Identity.
494pub async fn delete_identity_sessions(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentitySessionsError>> {
495    // add a prefix to parameters to efficiently prevent name collisions
496    let p_path_id = id;
497
498    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
499    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
500
501    if let Some(ref user_agent) = configuration.user_agent {
502        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
503    }
504    if let Some(ref token) = configuration.bearer_access_token {
505        req_builder = req_builder.bearer_auth(token.to_owned());
506    };
507
508    let req = req_builder.build()?;
509    let resp = configuration.client.execute(req).await?;
510
511    let status = resp.status();
512
513    if !status.is_client_error() && !status.is_server_error() {
514        Ok(())
515    } else {
516        let content = resp.text().await?;
517        let entity: Option<DeleteIdentitySessionsError> = serde_json::from_str(&content).ok();
518        Err(Error::ResponseError(ResponseContent { status, content, entity }))
519    }
520}
521
522/// Calling this endpoint deactivates the specified session. Session data is not deleted.
523pub async fn disable_session(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DisableSessionError>> {
524    // add a prefix to parameters to efficiently prevent name collisions
525    let p_path_id = id;
526
527    let uri_str = format!("{}/admin/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
528    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
529
530    if let Some(ref user_agent) = configuration.user_agent {
531        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
532    }
533    if let Some(ref token) = configuration.bearer_access_token {
534        req_builder = req_builder.bearer_auth(token.to_owned());
535    };
536
537    let req = req_builder.build()?;
538    let resp = configuration.client.execute(req).await?;
539
540    let status = resp.status();
541
542    if !status.is_client_error() && !status.is_server_error() {
543        Ok(())
544    } else {
545        let content = resp.text().await?;
546        let entity: Option<DisableSessionError> = serde_json::from_str(&content).ok();
547        Err(Error::ResponseError(ResponseContent { status, content, entity }))
548    }
549}
550
551/// Calling this endpoint extends the given session ID. If `session.earliest_possible_extend` is set it will only extend the session after the specified time has passed.  This endpoint returns per default a 204 No Content response on success. Older Ory Network projects may return a 200 OK response with the session in the body. Returning the session as part of the response will be deprecated in the future and should not be relied upon.  This endpoint ignores consecutive requests to extend the same session and returns a 404 error in those scenarios. This endpoint also returns 404 errors if the session does not exist.  Retrieve the session ID from the `/sessions/whoami` endpoint / `toSession` SDK method.
552pub async fn extend_session(configuration: &configuration::Configuration, id: &str) -> Result<models::Session, Error<ExtendSessionError>> {
553    // add a prefix to parameters to efficiently prevent name collisions
554    let p_path_id = id;
555
556    let uri_str = format!("{}/admin/sessions/{id}/extend", configuration.base_path, id=crate::apis::urlencode(p_path_id));
557    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
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(ref token) = configuration.bearer_access_token {
563        req_builder = req_builder.bearer_auth(token.to_owned());
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::Session`"))),
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::Session`")))),
583        }
584    } else {
585        let content = resp.text().await?;
586        let entity: Option<ExtendSessionError> = serde_json::from_str(&content).ok();
587        Err(Error::ResponseError(ResponseContent { status, content, entity }))
588    }
589}
590
591/// Return an [identity](https://www.ory.com/docs/kratos/concepts/identity-user-model) by its ID. You can optionally include credentials (e.g. social sign in connections) in the response by using the `include_credential` query parameter.
592pub async fn get_identity(configuration: &configuration::Configuration, id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityError>> {
593    // add a prefix to parameters to efficiently prevent name collisions
594    let p_path_id = id;
595    let p_query_include_credential = include_credential;
596
597    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
598    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
599
600    if let Some(ref param_value) = p_query_include_credential {
601        req_builder = match "multi" {
602            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
603            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
604        };
605    }
606    if let Some(ref user_agent) = configuration.user_agent {
607        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
608    }
609    if let Some(ref token) = configuration.bearer_access_token {
610        req_builder = req_builder.bearer_auth(token.to_owned());
611    };
612
613    let req = req_builder.build()?;
614    let resp = configuration.client.execute(req).await?;
615
616    let status = resp.status();
617    let content_type = resp
618        .headers()
619        .get("content-type")
620        .and_then(|v| v.to_str().ok())
621        .unwrap_or("application/octet-stream");
622    let content_type = super::ContentType::from(content_type);
623
624    if !status.is_client_error() && !status.is_server_error() {
625        let content = resp.text().await?;
626        match content_type {
627            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
628            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
629            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::Identity`")))),
630        }
631    } else {
632        let content = resp.text().await?;
633        let entity: Option<GetIdentityError> = serde_json::from_str(&content).ok();
634        Err(Error::ResponseError(ResponseContent { status, content, entity }))
635    }
636}
637
638/// Return an [identity](https://www.ory.com/docs/kratos/concepts/identity-user-model) by its external ID. You can optionally include credentials (e.g. social sign in connections) in the response by using the `include_credential` query parameter.
639pub async fn get_identity_by_external_id(configuration: &configuration::Configuration, external_id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityByExternalIdError>> {
640    // add a prefix to parameters to efficiently prevent name collisions
641    let p_path_external_id = external_id;
642    let p_query_include_credential = include_credential;
643
644    let uri_str = format!("{}/admin/identities/by/external/{externalID}", configuration.base_path, externalID=crate::apis::urlencode(p_path_external_id));
645    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
646
647    if let Some(ref param_value) = p_query_include_credential {
648        req_builder = match "multi" {
649            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
650            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
651        };
652    }
653    if let Some(ref user_agent) = configuration.user_agent {
654        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
655    }
656    if let Some(ref token) = configuration.bearer_access_token {
657        req_builder = req_builder.bearer_auth(token.to_owned());
658    };
659
660    let req = req_builder.build()?;
661    let resp = configuration.client.execute(req).await?;
662
663    let status = resp.status();
664    let content_type = resp
665        .headers()
666        .get("content-type")
667        .and_then(|v| v.to_str().ok())
668        .unwrap_or("application/octet-stream");
669    let content_type = super::ContentType::from(content_type);
670
671    if !status.is_client_error() && !status.is_server_error() {
672        let content = resp.text().await?;
673        match content_type {
674            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
675            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
676            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::Identity`")))),
677        }
678    } else {
679        let content = resp.text().await?;
680        let entity: Option<GetIdentityByExternalIdError> = serde_json::from_str(&content).ok();
681        Err(Error::ResponseError(ResponseContent { status, content, entity }))
682    }
683}
684
685/// Return a specific identity schema.
686pub async fn get_identity_schema(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<GetIdentitySchemaError>> {
687    // add a prefix to parameters to efficiently prevent name collisions
688    let p_path_id = id;
689
690    let uri_str = format!("{}/schemas/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
691    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
692
693    if let Some(ref user_agent) = configuration.user_agent {
694        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
695    }
696
697    let req = req_builder.build()?;
698    let resp = configuration.client.execute(req).await?;
699
700    let status = resp.status();
701    let content_type = resp
702        .headers()
703        .get("content-type")
704        .and_then(|v| v.to_str().ok())
705        .unwrap_or("application/octet-stream");
706    let content_type = super::ContentType::from(content_type);
707
708    if !status.is_client_error() && !status.is_server_error() {
709        let content = resp.text().await?;
710        match content_type {
711            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
712            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
713            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
714        }
715    } else {
716        let content = resp.text().await?;
717        let entity: Option<GetIdentitySchemaError> = serde_json::from_str(&content).ok();
718        Err(Error::ResponseError(ResponseContent { status, content, entity }))
719    }
720}
721
722/// This endpoint is useful for:  Getting a session object with all specified expandables that exist in an administrative context.
723pub async fn get_session(configuration: &configuration::Configuration, id: &str, expand: Option<Vec<String>>) -> Result<models::Session, Error<GetSessionError>> {
724    // add a prefix to parameters to efficiently prevent name collisions
725    let p_path_id = id;
726    let p_query_expand = expand;
727
728    let uri_str = format!("{}/admin/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
729    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
730
731    if let Some(ref param_value) = p_query_expand {
732        req_builder = match "multi" {
733            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
734            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
735        };
736    }
737    if let Some(ref user_agent) = configuration.user_agent {
738        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
739    }
740    if let Some(ref token) = configuration.bearer_access_token {
741        req_builder = req_builder.bearer_auth(token.to_owned());
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::Session`"))),
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::Session`")))),
761        }
762    } else {
763        let content = resp.text().await?;
764        let entity: Option<GetSessionError> = serde_json::from_str(&content).ok();
765        Err(Error::ResponseError(ResponseContent { status, content, entity }))
766    }
767}
768
769/// Lists all [identities](https://www.ory.com/docs/kratos/concepts/identity-user-model) in the system. Note: filters cannot be combined.
770pub async fn list_identities(configuration: &configuration::Configuration, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>, consistency: Option<&str>, ids: Option<Vec<String>>, credentials_identifier: Option<&str>, preview_credentials_identifier_similar: Option<&str>, include_credential: Option<Vec<String>>, organization_id: Option<&str>) -> Result<Vec<models::Identity>, Error<ListIdentitiesError>> {
771    // add a prefix to parameters to efficiently prevent name collisions
772    let p_query_per_page = per_page;
773    let p_query_page = page;
774    let p_query_page_size = page_size;
775    let p_query_page_token = page_token;
776    let p_query_consistency = consistency;
777    let p_query_ids = ids;
778    let p_query_credentials_identifier = credentials_identifier;
779    let p_query_preview_credentials_identifier_similar = preview_credentials_identifier_similar;
780    let p_query_include_credential = include_credential;
781    let p_query_organization_id = organization_id;
782
783    let uri_str = format!("{}/admin/identities", configuration.base_path);
784    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
785
786    if let Some(ref param_value) = p_query_per_page {
787        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
788    }
789    if let Some(ref param_value) = p_query_page {
790        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
791    }
792    if let Some(ref param_value) = p_query_page_size {
793        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
794    }
795    if let Some(ref param_value) = p_query_page_token {
796        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
797    }
798    if let Some(ref param_value) = p_query_consistency {
799        req_builder = req_builder.query(&[("consistency", &param_value.to_string())]);
800    }
801    if let Some(ref param_value) = p_query_ids {
802        req_builder = match "multi" {
803            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("ids".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
804            _ => req_builder.query(&[("ids", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
805        };
806    }
807    if let Some(ref param_value) = p_query_credentials_identifier {
808        req_builder = req_builder.query(&[("credentials_identifier", &param_value.to_string())]);
809    }
810    if let Some(ref param_value) = p_query_preview_credentials_identifier_similar {
811        req_builder = req_builder.query(&[("preview_credentials_identifier_similar", &param_value.to_string())]);
812    }
813    if let Some(ref param_value) = p_query_include_credential {
814        req_builder = match "multi" {
815            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
816            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
817        };
818    }
819    if let Some(ref param_value) = p_query_organization_id {
820        req_builder = req_builder.query(&[("organization_id", &param_value.to_string())]);
821    }
822    if let Some(ref user_agent) = configuration.user_agent {
823        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
824    }
825    if let Some(ref token) = configuration.bearer_access_token {
826        req_builder = req_builder.bearer_auth(token.to_owned());
827    };
828
829    let req = req_builder.build()?;
830    let resp = configuration.client.execute(req).await?;
831
832    let status = resp.status();
833    let content_type = resp
834        .headers()
835        .get("content-type")
836        .and_then(|v| v.to_str().ok())
837        .unwrap_or("application/octet-stream");
838    let content_type = super::ContentType::from(content_type);
839
840    if !status.is_client_error() && !status.is_server_error() {
841        let content = resp.text().await?;
842        match content_type {
843            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
844            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Identity&gt;`"))),
845            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::Identity&gt;`")))),
846        }
847    } else {
848        let content = resp.text().await?;
849        let entity: Option<ListIdentitiesError> = serde_json::from_str(&content).ok();
850        Err(Error::ResponseError(ResponseContent { status, content, entity }))
851    }
852}
853
854/// Returns a list of all identity schemas currently in use.
855pub async fn list_identity_schemas(configuration: &configuration::Configuration, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>) -> Result<Vec<models::IdentitySchemaContainer>, Error<ListIdentitySchemasError>> {
856    // add a prefix to parameters to efficiently prevent name collisions
857    let p_query_per_page = per_page;
858    let p_query_page = page;
859    let p_query_page_size = page_size;
860    let p_query_page_token = page_token;
861
862    let uri_str = format!("{}/schemas", configuration.base_path);
863    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
864
865    if let Some(ref param_value) = p_query_per_page {
866        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
867    }
868    if let Some(ref param_value) = p_query_page {
869        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
870    }
871    if let Some(ref param_value) = p_query_page_size {
872        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
873    }
874    if let Some(ref param_value) = p_query_page_token {
875        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
876    }
877    if let Some(ref user_agent) = configuration.user_agent {
878        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
879    }
880
881    let req = req_builder.build()?;
882    let resp = configuration.client.execute(req).await?;
883
884    let status = resp.status();
885    let content_type = resp
886        .headers()
887        .get("content-type")
888        .and_then(|v| v.to_str().ok())
889        .unwrap_or("application/octet-stream");
890    let content_type = super::ContentType::from(content_type);
891
892    if !status.is_client_error() && !status.is_server_error() {
893        let content = resp.text().await?;
894        match content_type {
895            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
896            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::IdentitySchemaContainer&gt;`"))),
897            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::IdentitySchemaContainer&gt;`")))),
898        }
899    } else {
900        let content = resp.text().await?;
901        let entity: Option<ListIdentitySchemasError> = serde_json::from_str(&content).ok();
902        Err(Error::ResponseError(ResponseContent { status, content, entity }))
903    }
904}
905
906/// This endpoint returns all sessions that belong to the given Identity.
907pub async fn list_identity_sessions(configuration: &configuration::Configuration, id: &str, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>, active: Option<bool>) -> Result<Vec<models::Session>, Error<ListIdentitySessionsError>> {
908    // add a prefix to parameters to efficiently prevent name collisions
909    let p_path_id = id;
910    let p_query_per_page = per_page;
911    let p_query_page = page;
912    let p_query_page_size = page_size;
913    let p_query_page_token = page_token;
914    let p_query_active = active;
915
916    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
917    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
918
919    if let Some(ref param_value) = p_query_per_page {
920        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
921    }
922    if let Some(ref param_value) = p_query_page {
923        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
924    }
925    if let Some(ref param_value) = p_query_page_size {
926        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
927    }
928    if let Some(ref param_value) = p_query_page_token {
929        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
930    }
931    if let Some(ref param_value) = p_query_active {
932        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
933    }
934    if let Some(ref user_agent) = configuration.user_agent {
935        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
936    }
937    if let Some(ref token) = configuration.bearer_access_token {
938        req_builder = req_builder.bearer_auth(token.to_owned());
939    };
940
941    let req = req_builder.build()?;
942    let resp = configuration.client.execute(req).await?;
943
944    let status = resp.status();
945    let content_type = resp
946        .headers()
947        .get("content-type")
948        .and_then(|v| v.to_str().ok())
949        .unwrap_or("application/octet-stream");
950    let content_type = super::ContentType::from(content_type);
951
952    if !status.is_client_error() && !status.is_server_error() {
953        let content = resp.text().await?;
954        match content_type {
955            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
956            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;`"))),
957            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;`")))),
958        }
959    } else {
960        let content = resp.text().await?;
961        let entity: Option<ListIdentitySessionsError> = serde_json::from_str(&content).ok();
962        Err(Error::ResponseError(ResponseContent { status, content, entity }))
963    }
964}
965
966/// Listing all sessions that exist.
967pub async fn list_sessions(configuration: &configuration::Configuration, page_size: Option<i64>, page_token: Option<&str>, active: Option<bool>, expand: Option<Vec<String>>) -> Result<Vec<models::Session>, Error<ListSessionsError>> {
968    // add a prefix to parameters to efficiently prevent name collisions
969    let p_query_page_size = page_size;
970    let p_query_page_token = page_token;
971    let p_query_active = active;
972    let p_query_expand = expand;
973
974    let uri_str = format!("{}/admin/sessions", configuration.base_path);
975    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
976
977    if let Some(ref param_value) = p_query_page_size {
978        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
979    }
980    if let Some(ref param_value) = p_query_page_token {
981        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
982    }
983    if let Some(ref param_value) = p_query_active {
984        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
985    }
986    if let Some(ref param_value) = p_query_expand {
987        req_builder = match "multi" {
988            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
989            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
990        };
991    }
992    if let Some(ref user_agent) = configuration.user_agent {
993        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
994    }
995    if let Some(ref token) = configuration.bearer_access_token {
996        req_builder = req_builder.bearer_auth(token.to_owned());
997    };
998
999    let req = req_builder.build()?;
1000    let resp = configuration.client.execute(req).await?;
1001
1002    let status = resp.status();
1003    let content_type = resp
1004        .headers()
1005        .get("content-type")
1006        .and_then(|v| v.to_str().ok())
1007        .unwrap_or("application/octet-stream");
1008    let content_type = super::ContentType::from(content_type);
1009
1010    if !status.is_client_error() && !status.is_server_error() {
1011        let content = resp.text().await?;
1012        match content_type {
1013            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1014            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;`"))),
1015            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;`")))),
1016        }
1017    } else {
1018        let content = resp.text().await?;
1019        let entity: Option<ListSessionsError> = serde_json::from_str(&content).ok();
1020        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1021    }
1022}
1023
1024/// Disable or delete sessions for a list of identities or a list of sessions in a single call. The `action` field selects the operation:  `disable` — deactivate matching sessions (sets `active = false`, preserves audit data). `delete` — permanently delete matching sessions.  Exactly one of `identities` or `sessions` must be provided. To scope the operation to every session in the network, pass `identities: [\"*\"]`; the wildcard is not accepted in the `sessions` field. Up to 500 explicit IDs are accepted per call.  All requests return `200 OK` with `{processed, more}`. `processed` reports how many rows the call affected; for `disable` it counts only sessions that were active before the call. `more` is `true` only when a wildcard request reached the per-call batch limit and additional rows may remain; callers drain the network by re-issuing the same request while `more` is `true`. Explicit-IDs requests always return `more: false`.
1025pub async fn manage_sessions(configuration: &configuration::Configuration, manage_sessions_body: models::ManageSessionsBody) -> Result<models::ManageSessionsResponse, Error<ManageSessionsError>> {
1026    // add a prefix to parameters to efficiently prevent name collisions
1027    let p_body_manage_sessions_body = manage_sessions_body;
1028
1029    let uri_str = format!("{}/admin/sessions", configuration.base_path);
1030    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1031
1032    if let Some(ref user_agent) = configuration.user_agent {
1033        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1034    }
1035    if let Some(ref token) = configuration.bearer_access_token {
1036        req_builder = req_builder.bearer_auth(token.to_owned());
1037    };
1038    req_builder = req_builder.json(&p_body_manage_sessions_body);
1039
1040    let req = req_builder.build()?;
1041    let resp = configuration.client.execute(req).await?;
1042
1043    let status = resp.status();
1044    let content_type = resp
1045        .headers()
1046        .get("content-type")
1047        .and_then(|v| v.to_str().ok())
1048        .unwrap_or("application/octet-stream");
1049    let content_type = super::ContentType::from(content_type);
1050
1051    if !status.is_client_error() && !status.is_server_error() {
1052        let content = resp.text().await?;
1053        match content_type {
1054            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1055            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManageSessionsResponse`"))),
1056            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::ManageSessionsResponse`")))),
1057        }
1058    } else {
1059        let content = resp.text().await?;
1060        let entity: Option<ManageSessionsError> = serde_json::from_str(&content).ok();
1061        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1062    }
1063}
1064
1065/// Partially updates an [identity's](https://www.ory.com/docs/kratos/concepts/identity-user-model) field using [JSON Patch](https://jsonpatch.com/). The fields `id`, `stateChangedAt` and `credentials` can not be updated using this method.
1066pub async fn patch_identity(configuration: &configuration::Configuration, id: &str, json_patch: Option<Vec<models::JsonPatch>>) -> Result<models::Identity, Error<PatchIdentityError>> {
1067    // add a prefix to parameters to efficiently prevent name collisions
1068    let p_path_id = id;
1069    let p_body_json_patch = json_patch;
1070
1071    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1072    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
1073
1074    if let Some(ref user_agent) = configuration.user_agent {
1075        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1076    }
1077    if let Some(ref token) = configuration.bearer_access_token {
1078        req_builder = req_builder.bearer_auth(token.to_owned());
1079    };
1080    req_builder = req_builder.json(&p_body_json_patch);
1081
1082    let req = req_builder.build()?;
1083    let resp = configuration.client.execute(req).await?;
1084
1085    let status = resp.status();
1086    let content_type = resp
1087        .headers()
1088        .get("content-type")
1089        .and_then(|v| v.to_str().ok())
1090        .unwrap_or("application/octet-stream");
1091    let content_type = super::ContentType::from(content_type);
1092
1093    if !status.is_client_error() && !status.is_server_error() {
1094        let content = resp.text().await?;
1095        match content_type {
1096            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1097            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1098            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::Identity`")))),
1099        }
1100    } else {
1101        let content = resp.text().await?;
1102        let entity: Option<PatchIdentityError> = serde_json::from_str(&content).ok();
1103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1104    }
1105}
1106
1107/// This endpoint updates an [identity](https://www.ory.com/docs/kratos/concepts/identity-user-model). The full identity payload (except credentials) is expected.  It is possible to update the identity's credentials as well. Using this operation, credentials will not be overwritten but instead added to the list. For example, if a user has a social sign in connection set up, updating the credentials will keep the social sign in connection and add the new credentials to the list. This prevents accidentally overwriting credentials and locking out users. A complete view of all credential types is here:  `password`: The existing password credential will be completely replaced with the new configuration. You can provide either a hashed password, a plaintext password (which will be hashed), or enable the password migration hook. `oidc`, `saml`: The existing OIDC and SAML credentials will be kept and the new credentials will be added to the list. `totp`: The existing TOTP credentials will be replaced with the new configuration. `lookup_secret`: The existing Lookup Secret codes will be kept and the new codes will be added to the list. `webauthn`, `passkey`: The existing credentials are preserved, new credentials are added, and credentials with matching IDs are updated with new values. If a new `user_handle` is provided, it's added to the identity's identifiers list while preserving previous user handles. `code`: To import code credentials, configure your identity schema to use one of the identity traits as an identifier source (`{\"ory.sh/kratos\":{\"code\":{\"identifier\":true\", \"via\":\"email\"}}}`).
1108pub async fn update_identity(configuration: &configuration::Configuration, id: &str, update_identity_body: Option<models::UpdateIdentityBody>) -> Result<models::Identity, Error<UpdateIdentityError>> {
1109    // add a prefix to parameters to efficiently prevent name collisions
1110    let p_path_id = id;
1111    let p_body_update_identity_body = update_identity_body;
1112
1113    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1114    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1115
1116    if let Some(ref user_agent) = configuration.user_agent {
1117        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1118    }
1119    if let Some(ref token) = configuration.bearer_access_token {
1120        req_builder = req_builder.bearer_auth(token.to_owned());
1121    };
1122    req_builder = req_builder.json(&p_body_update_identity_body);
1123
1124    let req = req_builder.build()?;
1125    let resp = configuration.client.execute(req).await?;
1126
1127    let status = resp.status();
1128    let content_type = resp
1129        .headers()
1130        .get("content-type")
1131        .and_then(|v| v.to_str().ok())
1132        .unwrap_or("application/octet-stream");
1133    let content_type = super::ContentType::from(content_type);
1134
1135    if !status.is_client_error() && !status.is_server_error() {
1136        let content = resp.text().await?;
1137        match content_type {
1138            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1139            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1140            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::Identity`")))),
1141        }
1142    } else {
1143        let content = resp.text().await?;
1144        let entity: Option<UpdateIdentityError> = serde_json::from_str(&content).ok();
1145        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1146    }
1147}
1148