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.92
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    Status400(models::ErrorGeneric),
82    Status404(models::ErrorGeneric),
83    DefaultResponse(models::ErrorGeneric),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`delete_identity_sessions`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum DeleteIdentitySessionsError {
91    Status400(models::ErrorGeneric),
92    Status401(models::ErrorGeneric),
93    Status404(models::ErrorGeneric),
94    DefaultResponse(models::ErrorGeneric),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`disable_session`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum DisableSessionError {
102    Status400(models::ErrorGeneric),
103    Status401(models::ErrorGeneric),
104    DefaultResponse(models::ErrorGeneric),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`extend_session`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum ExtendSessionError {
112    Status400(models::ErrorGeneric),
113    Status404(models::ErrorGeneric),
114    DefaultResponse(models::ErrorGeneric),
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`get_identity`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum GetIdentityError {
122    Status404(models::ErrorGeneric),
123    DefaultResponse(models::ErrorGeneric),
124    UnknownValue(serde_json::Value),
125}
126
127/// struct for typed errors of method [`get_identity_by_external_id`]
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum GetIdentityByExternalIdError {
131    Status404(models::ErrorGeneric),
132    DefaultResponse(models::ErrorGeneric),
133    UnknownValue(serde_json::Value),
134}
135
136/// struct for typed errors of method [`get_identity_schema`]
137#[derive(Debug, Clone, Serialize, Deserialize)]
138#[serde(untagged)]
139pub enum GetIdentitySchemaError {
140    Status404(models::ErrorGeneric),
141    DefaultResponse(models::ErrorGeneric),
142    UnknownValue(serde_json::Value),
143}
144
145/// struct for typed errors of method [`get_session`]
146#[derive(Debug, Clone, Serialize, Deserialize)]
147#[serde(untagged)]
148pub enum GetSessionError {
149    Status400(models::ErrorGeneric),
150    DefaultResponse(models::ErrorGeneric),
151    UnknownValue(serde_json::Value),
152}
153
154/// struct for typed errors of method [`list_identities`]
155#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(untagged)]
157pub enum ListIdentitiesError {
158    DefaultResponse(models::ErrorGeneric),
159    UnknownValue(serde_json::Value),
160}
161
162/// struct for typed errors of method [`list_identity_schemas`]
163#[derive(Debug, Clone, Serialize, Deserialize)]
164#[serde(untagged)]
165pub enum ListIdentitySchemasError {
166    DefaultResponse(models::ErrorGeneric),
167    UnknownValue(serde_json::Value),
168}
169
170/// struct for typed errors of method [`list_identity_sessions`]
171#[derive(Debug, Clone, Serialize, Deserialize)]
172#[serde(untagged)]
173pub enum ListIdentitySessionsError {
174    Status400(models::ErrorGeneric),
175    Status404(models::ErrorGeneric),
176    DefaultResponse(models::ErrorGeneric),
177    UnknownValue(serde_json::Value),
178}
179
180/// struct for typed errors of method [`list_sessions`]
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum ListSessionsError {
184    Status400(models::ErrorGeneric),
185    DefaultResponse(models::ErrorGeneric),
186    UnknownValue(serde_json::Value),
187}
188
189/// struct for typed errors of method [`manage_sessions`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum ManageSessionsError {
193    Status400(models::ErrorGeneric),
194    Status401(models::ErrorGeneric),
195    DefaultResponse(models::ErrorGeneric),
196    UnknownValue(serde_json::Value),
197}
198
199/// struct for typed errors of method [`patch_identity`]
200#[derive(Debug, Clone, Serialize, Deserialize)]
201#[serde(untagged)]
202pub enum PatchIdentityError {
203    Status400(models::ErrorGeneric),
204    Status404(models::ErrorGeneric),
205    Status409(models::ErrorGeneric),
206    DefaultResponse(models::ErrorGeneric),
207    UnknownValue(serde_json::Value),
208}
209
210/// struct for typed errors of method [`update_identity`]
211#[derive(Debug, Clone, Serialize, Deserialize)]
212#[serde(untagged)]
213pub enum UpdateIdentityError {
214    Status400(models::ErrorGeneric),
215    Status404(models::ErrorGeneric),
216    Status409(models::ErrorGeneric),
217    DefaultResponse(models::ErrorGeneric),
218    UnknownValue(serde_json::Value),
219}
220
221
222/// 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.  This applies while `with_partial_inserts` is true, which is the default. Set it to false to import the batch as a single unit instead: one conflict then fails the whole request with 409 Conflict and no identity is created, in exchange for a considerably faster import.  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.
223pub async fn batch_patch_identities(configuration: &configuration::Configuration, patch_identities_body: Option<models::PatchIdentitiesBody>) -> Result<models::BatchPatchIdentitiesResponse, Error<BatchPatchIdentitiesError>> {
224    // add a prefix to parameters to efficiently prevent name collisions
225    let p_body_patch_identities_body = patch_identities_body;
226
227    let uri_str = format!("{}/admin/identities", configuration.base_path);
228    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
229
230    if let Some(ref user_agent) = configuration.user_agent {
231        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
232    }
233    if let Some(ref token) = configuration.bearer_access_token {
234        req_builder = req_builder.bearer_auth(token.to_owned());
235    };
236    req_builder = req_builder.json(&p_body_patch_identities_body);
237
238    let req = req_builder.build()?;
239    let resp = configuration.client.execute(req).await?;
240
241    let status = resp.status();
242    let content_type = resp
243        .headers()
244        .get("content-type")
245        .and_then(|v| v.to_str().ok())
246        .unwrap_or("application/octet-stream");
247    let content_type = super::ContentType::from(content_type);
248
249    if !status.is_client_error() && !status.is_server_error() {
250        let content = resp.text().await?;
251        match content_type {
252            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
253            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchPatchIdentitiesResponse`"))),
254            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`")))),
255        }
256    } else {
257        let content = resp.text().await?;
258        let entity: Option<BatchPatchIdentitiesError> = serde_json::from_str(&content).ok();
259        Err(Error::ResponseError(ResponseContent { status, content, entity }))
260    }
261}
262
263/// 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.
264pub async fn create_identity(configuration: &configuration::Configuration, create_identity_body: Option<models::CreateIdentityBody>) -> Result<models::Identity, Error<CreateIdentityError>> {
265    // add a prefix to parameters to efficiently prevent name collisions
266    let p_body_create_identity_body = create_identity_body;
267
268    let uri_str = format!("{}/admin/identities", configuration.base_path);
269    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
270
271    if let Some(ref user_agent) = configuration.user_agent {
272        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
273    }
274    if let Some(ref token) = configuration.bearer_access_token {
275        req_builder = req_builder.bearer_auth(token.to_owned());
276    };
277    req_builder = req_builder.json(&p_body_create_identity_body);
278
279    let req = req_builder.build()?;
280    let resp = configuration.client.execute(req).await?;
281
282    let status = resp.status();
283    let content_type = resp
284        .headers()
285        .get("content-type")
286        .and_then(|v| v.to_str().ok())
287        .unwrap_or("application/octet-stream");
288    let content_type = super::ContentType::from(content_type);
289
290    if !status.is_client_error() && !status.is_server_error() {
291        let content = resp.text().await?;
292        match content_type {
293            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
294            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
295            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`")))),
296        }
297    } else {
298        let content = resp.text().await?;
299        let entity: Option<CreateIdentityError> = serde_json::from_str(&content).ok();
300        Err(Error::ResponseError(ResponseContent { status, content, entity }))
301    }
302}
303
304/// This endpoint creates a recovery code which should be given to the user in order for them to recover (or activate) their account.
305pub async fn create_recovery_code_for_identity(configuration: &configuration::Configuration, create_recovery_code_for_identity_body: Option<models::CreateRecoveryCodeForIdentityBody>) -> Result<models::RecoveryCodeForIdentity, Error<CreateRecoveryCodeForIdentityError>> {
306    // add a prefix to parameters to efficiently prevent name collisions
307    let p_body_create_recovery_code_for_identity_body = create_recovery_code_for_identity_body;
308
309    let uri_str = format!("{}/admin/recovery/code", configuration.base_path);
310    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
311
312    if let Some(ref user_agent) = configuration.user_agent {
313        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
314    }
315    if let Some(ref token) = configuration.bearer_access_token {
316        req_builder = req_builder.bearer_auth(token.to_owned());
317    };
318    req_builder = req_builder.json(&p_body_create_recovery_code_for_identity_body);
319
320    let req = req_builder.build()?;
321    let resp = configuration.client.execute(req).await?;
322
323    let status = resp.status();
324    let content_type = resp
325        .headers()
326        .get("content-type")
327        .and_then(|v| v.to_str().ok())
328        .unwrap_or("application/octet-stream");
329    let content_type = super::ContentType::from(content_type);
330
331    if !status.is_client_error() && !status.is_server_error() {
332        let content = resp.text().await?;
333        match content_type {
334            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
335            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryCodeForIdentity`"))),
336            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`")))),
337        }
338    } else {
339        let content = resp.text().await?;
340        let entity: Option<CreateRecoveryCodeForIdentityError> = serde_json::from_str(&content).ok();
341        Err(Error::ResponseError(ResponseContent { status, content, entity }))
342    }
343}
344
345/// This endpoint creates a recovery link which should be given to the user in order for them to recover (or activate) their account.
346pub 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>> {
347    // add a prefix to parameters to efficiently prevent name collisions
348    let p_query_return_to = return_to;
349    let p_body_create_recovery_link_for_identity_body = create_recovery_link_for_identity_body;
350
351    let uri_str = format!("{}/admin/recovery/link", configuration.base_path);
352    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
353
354    if let Some(ref param_value) = p_query_return_to {
355        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
356    }
357    if let Some(ref user_agent) = configuration.user_agent {
358        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
359    }
360    if let Some(ref token) = configuration.bearer_access_token {
361        req_builder = req_builder.bearer_auth(token.to_owned());
362    };
363    req_builder = req_builder.json(&p_body_create_recovery_link_for_identity_body);
364
365    let req = req_builder.build()?;
366    let resp = configuration.client.execute(req).await?;
367
368    let status = resp.status();
369    let content_type = resp
370        .headers()
371        .get("content-type")
372        .and_then(|v| v.to_str().ok())
373        .unwrap_or("application/octet-stream");
374    let content_type = super::ContentType::from(content_type);
375
376    if !status.is_client_error() && !status.is_server_error() {
377        let content = resp.text().await?;
378        match content_type {
379            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
380            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryLinkForIdentity`"))),
381            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`")))),
382        }
383    } else {
384        let content = resp.text().await?;
385        let entity: Option<CreateRecoveryLinkForIdentityError> = serde_json::from_str(&content).ok();
386        Err(Error::ResponseError(ResponseContent { status, content, entity }))
387    }
388}
389
390/// 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.
391pub async fn create_test_login_flow(configuration: &configuration::Configuration, create_test_login_flow_body: models::CreateTestLoginFlowBody) -> Result<models::LoginFlow, Error<CreateTestLoginFlowError>> {
392    // add a prefix to parameters to efficiently prevent name collisions
393    let p_body_create_test_login_flow_body = create_test_login_flow_body;
394
395    let uri_str = format!("{}/admin/test-login-flows", configuration.base_path);
396    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
397
398    if let Some(ref user_agent) = configuration.user_agent {
399        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
400    }
401    if let Some(ref token) = configuration.bearer_access_token {
402        req_builder = req_builder.bearer_auth(token.to_owned());
403    };
404    req_builder = req_builder.json(&p_body_create_test_login_flow_body);
405
406    let req = req_builder.build()?;
407    let resp = configuration.client.execute(req).await?;
408
409    let status = resp.status();
410    let content_type = resp
411        .headers()
412        .get("content-type")
413        .and_then(|v| v.to_str().ok())
414        .unwrap_or("application/octet-stream");
415    let content_type = super::ContentType::from(content_type);
416
417    if !status.is_client_error() && !status.is_server_error() {
418        let content = resp.text().await?;
419        match content_type {
420            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
421            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginFlow`"))),
422            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`")))),
423        }
424    } else {
425        let content = resp.text().await?;
426        let entity: Option<CreateTestLoginFlowError> = serde_json::from_str(&content).ok();
427        Err(Error::ResponseError(ResponseContent { status, content, entity }))
428    }
429}
430
431/// 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.
432pub async fn delete_identity(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentityError>> {
433    // add a prefix to parameters to efficiently prevent name collisions
434    let p_path_id = id;
435
436    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
437    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
438
439    if let Some(ref user_agent) = configuration.user_agent {
440        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
441    }
442    if let Some(ref token) = configuration.bearer_access_token {
443        req_builder = req_builder.bearer_auth(token.to_owned());
444    };
445
446    let req = req_builder.build()?;
447    let resp = configuration.client.execute(req).await?;
448
449    let status = resp.status();
450
451    if !status.is_client_error() && !status.is_server_error() {
452        Ok(())
453    } else {
454        let content = resp.text().await?;
455        let entity: Option<DeleteIdentityError> = serde_json::from_str(&content).ok();
456        Err(Error::ResponseError(ResponseContent { status, content, entity }))
457    }
458}
459
460/// 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.
461pub async fn delete_identity_credentials(configuration: &configuration::Configuration, id: &str, r#type: &str, identifier: Option<&str>) -> Result<(), Error<DeleteIdentityCredentialsError>> {
462    // add a prefix to parameters to efficiently prevent name collisions
463    let p_path_id = id;
464    let p_path_type = r#type;
465    let p_query_identifier = identifier;
466
467    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));
468    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
469
470    if let Some(ref param_value) = p_query_identifier {
471        req_builder = req_builder.query(&[("identifier", &param_value.to_string())]);
472    }
473    if let Some(ref user_agent) = configuration.user_agent {
474        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
475    }
476    if let Some(ref token) = configuration.bearer_access_token {
477        req_builder = req_builder.bearer_auth(token.to_owned());
478    };
479
480    let req = req_builder.build()?;
481    let resp = configuration.client.execute(req).await?;
482
483    let status = resp.status();
484
485    if !status.is_client_error() && !status.is_server_error() {
486        Ok(())
487    } else {
488        let content = resp.text().await?;
489        let entity: Option<DeleteIdentityCredentialsError> = serde_json::from_str(&content).ok();
490        Err(Error::ResponseError(ResponseContent { status, content, entity }))
491    }
492}
493
494/// Calling this endpoint irrecoverably and permanently deletes and invalidates all sessions that belong to the given Identity.
495pub async fn delete_identity_sessions(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentitySessionsError>> {
496    // add a prefix to parameters to efficiently prevent name collisions
497    let p_path_id = id;
498
499    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
500    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
501
502    if let Some(ref user_agent) = configuration.user_agent {
503        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
504    }
505    if let Some(ref token) = configuration.bearer_access_token {
506        req_builder = req_builder.bearer_auth(token.to_owned());
507    };
508
509    let req = req_builder.build()?;
510    let resp = configuration.client.execute(req).await?;
511
512    let status = resp.status();
513
514    if !status.is_client_error() && !status.is_server_error() {
515        Ok(())
516    } else {
517        let content = resp.text().await?;
518        let entity: Option<DeleteIdentitySessionsError> = serde_json::from_str(&content).ok();
519        Err(Error::ResponseError(ResponseContent { status, content, entity }))
520    }
521}
522
523/// Calling this endpoint deactivates the specified session. Session data is not deleted.
524pub async fn disable_session(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DisableSessionError>> {
525    // add a prefix to parameters to efficiently prevent name collisions
526    let p_path_id = id;
527
528    let uri_str = format!("{}/admin/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
529    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
530
531    if let Some(ref user_agent) = configuration.user_agent {
532        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
533    }
534    if let Some(ref token) = configuration.bearer_access_token {
535        req_builder = req_builder.bearer_auth(token.to_owned());
536    };
537
538    let req = req_builder.build()?;
539    let resp = configuration.client.execute(req).await?;
540
541    let status = resp.status();
542
543    if !status.is_client_error() && !status.is_server_error() {
544        Ok(())
545    } else {
546        let content = resp.text().await?;
547        let entity: Option<DisableSessionError> = serde_json::from_str(&content).ok();
548        Err(Error::ResponseError(ResponseContent { status, content, entity }))
549    }
550}
551
552/// 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 returns a success response without extending the session if the session is not yet due for an extension, including when a consecutive or concurrent request already extended it. This endpoint returns a 404 error if the session does not exist.  Retrieve the session ID from the `/sessions/whoami` endpoint / `toSession` SDK method.
553pub async fn extend_session(configuration: &configuration::Configuration, id: &str) -> Result<models::Session, Error<ExtendSessionError>> {
554    // add a prefix to parameters to efficiently prevent name collisions
555    let p_path_id = id;
556
557    let uri_str = format!("{}/admin/sessions/{id}/extend", configuration.base_path, id=crate::apis::urlencode(p_path_id));
558    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
559
560    if let Some(ref user_agent) = configuration.user_agent {
561        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
562    }
563    if let Some(ref token) = configuration.bearer_access_token {
564        req_builder = req_builder.bearer_auth(token.to_owned());
565    };
566
567    let req = req_builder.build()?;
568    let resp = configuration.client.execute(req).await?;
569
570    let status = resp.status();
571    let content_type = resp
572        .headers()
573        .get("content-type")
574        .and_then(|v| v.to_str().ok())
575        .unwrap_or("application/octet-stream");
576    let content_type = super::ContentType::from(content_type);
577
578    if !status.is_client_error() && !status.is_server_error() {
579        let content = resp.text().await?;
580        match content_type {
581            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
582            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Session`"))),
583            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`")))),
584        }
585    } else {
586        let content = resp.text().await?;
587        let entity: Option<ExtendSessionError> = serde_json::from_str(&content).ok();
588        Err(Error::ResponseError(ResponseContent { status, content, entity }))
589    }
590}
591
592/// 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.
593pub async fn get_identity(configuration: &configuration::Configuration, id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityError>> {
594    // add a prefix to parameters to efficiently prevent name collisions
595    let p_path_id = id;
596    let p_query_include_credential = include_credential;
597
598    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
599    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
600
601    if let Some(ref param_value) = p_query_include_credential {
602        req_builder = match "multi" {
603            "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)>>()),
604            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
605        };
606    }
607    if let Some(ref user_agent) = configuration.user_agent {
608        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
609    }
610    if let Some(ref token) = configuration.bearer_access_token {
611        req_builder = req_builder.bearer_auth(token.to_owned());
612    };
613
614    let req = req_builder.build()?;
615    let resp = configuration.client.execute(req).await?;
616
617    let status = resp.status();
618    let content_type = resp
619        .headers()
620        .get("content-type")
621        .and_then(|v| v.to_str().ok())
622        .unwrap_or("application/octet-stream");
623    let content_type = super::ContentType::from(content_type);
624
625    if !status.is_client_error() && !status.is_server_error() {
626        let content = resp.text().await?;
627        match content_type {
628            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
629            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
630            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`")))),
631        }
632    } else {
633        let content = resp.text().await?;
634        let entity: Option<GetIdentityError> = serde_json::from_str(&content).ok();
635        Err(Error::ResponseError(ResponseContent { status, content, entity }))
636    }
637}
638
639/// 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.
640pub async fn get_identity_by_external_id(configuration: &configuration::Configuration, external_id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityByExternalIdError>> {
641    // add a prefix to parameters to efficiently prevent name collisions
642    let p_path_external_id = external_id;
643    let p_query_include_credential = include_credential;
644
645    let uri_str = format!("{}/admin/identities/by/external/{externalID}", configuration.base_path, externalID=crate::apis::urlencode(p_path_external_id));
646    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
647
648    if let Some(ref param_value) = p_query_include_credential {
649        req_builder = match "multi" {
650            "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)>>()),
651            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
652        };
653    }
654    if let Some(ref user_agent) = configuration.user_agent {
655        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
656    }
657    if let Some(ref token) = configuration.bearer_access_token {
658        req_builder = req_builder.bearer_auth(token.to_owned());
659    };
660
661    let req = req_builder.build()?;
662    let resp = configuration.client.execute(req).await?;
663
664    let status = resp.status();
665    let content_type = resp
666        .headers()
667        .get("content-type")
668        .and_then(|v| v.to_str().ok())
669        .unwrap_or("application/octet-stream");
670    let content_type = super::ContentType::from(content_type);
671
672    if !status.is_client_error() && !status.is_server_error() {
673        let content = resp.text().await?;
674        match content_type {
675            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
676            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
677            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`")))),
678        }
679    } else {
680        let content = resp.text().await?;
681        let entity: Option<GetIdentityByExternalIdError> = serde_json::from_str(&content).ok();
682        Err(Error::ResponseError(ResponseContent { status, content, entity }))
683    }
684}
685
686/// Return a specific identity schema.
687pub async fn get_identity_schema(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<GetIdentitySchemaError>> {
688    // add a prefix to parameters to efficiently prevent name collisions
689    let p_path_id = id;
690
691    let uri_str = format!("{}/schemas/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
692    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
693
694    if let Some(ref user_agent) = configuration.user_agent {
695        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
696    }
697
698    let req = req_builder.build()?;
699    let resp = configuration.client.execute(req).await?;
700
701    let status = resp.status();
702    let content_type = resp
703        .headers()
704        .get("content-type")
705        .and_then(|v| v.to_str().ok())
706        .unwrap_or("application/octet-stream");
707    let content_type = super::ContentType::from(content_type);
708
709    if !status.is_client_error() && !status.is_server_error() {
710        let content = resp.text().await?;
711        match content_type {
712            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
713            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
714            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`")))),
715        }
716    } else {
717        let content = resp.text().await?;
718        let entity: Option<GetIdentitySchemaError> = serde_json::from_str(&content).ok();
719        Err(Error::ResponseError(ResponseContent { status, content, entity }))
720    }
721}
722
723/// This endpoint is useful for:  - Getting a session object with all specified expandables that exist in an administrative context.
724pub async fn get_session(configuration: &configuration::Configuration, id: &str, expand: Option<Vec<String>>) -> Result<models::Session, Error<GetSessionError>> {
725    // add a prefix to parameters to efficiently prevent name collisions
726    let p_path_id = id;
727    let p_query_expand = expand;
728
729    let uri_str = format!("{}/admin/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
730    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
731
732    if let Some(ref param_value) = p_query_expand {
733        req_builder = match "multi" {
734            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
735            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
736        };
737    }
738    if let Some(ref user_agent) = configuration.user_agent {
739        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
740    }
741    if let Some(ref token) = configuration.bearer_access_token {
742        req_builder = req_builder.bearer_auth(token.to_owned());
743    };
744
745    let req = req_builder.build()?;
746    let resp = configuration.client.execute(req).await?;
747
748    let status = resp.status();
749    let content_type = resp
750        .headers()
751        .get("content-type")
752        .and_then(|v| v.to_str().ok())
753        .unwrap_or("application/octet-stream");
754    let content_type = super::ContentType::from(content_type);
755
756    if !status.is_client_error() && !status.is_server_error() {
757        let content = resp.text().await?;
758        match content_type {
759            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
760            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Session`"))),
761            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`")))),
762        }
763    } else {
764        let content = resp.text().await?;
765        let entity: Option<GetSessionError> = serde_json::from_str(&content).ok();
766        Err(Error::ResponseError(ResponseContent { status, content, entity }))
767    }
768}
769
770/// Lists all [identities](https://www.ory.com/docs/kratos/concepts/identity-user-model) in the system. Note: filters cannot be combined.
771pub 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>> {
772    // add a prefix to parameters to efficiently prevent name collisions
773    let p_query_per_page = per_page;
774    let p_query_page = page;
775    let p_query_page_size = page_size;
776    let p_query_page_token = page_token;
777    let p_query_consistency = consistency;
778    let p_query_ids = ids;
779    let p_query_credentials_identifier = credentials_identifier;
780    let p_query_preview_credentials_identifier_similar = preview_credentials_identifier_similar;
781    let p_query_include_credential = include_credential;
782    let p_query_organization_id = organization_id;
783
784    let uri_str = format!("{}/admin/identities", configuration.base_path);
785    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
786
787    if let Some(ref param_value) = p_query_per_page {
788        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
789    }
790    if let Some(ref param_value) = p_query_page {
791        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
792    }
793    if let Some(ref param_value) = p_query_page_size {
794        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
795    }
796    if let Some(ref param_value) = p_query_page_token {
797        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
798    }
799    if let Some(ref param_value) = p_query_consistency {
800        req_builder = req_builder.query(&[("consistency", &param_value.to_string())]);
801    }
802    if let Some(ref param_value) = p_query_ids {
803        req_builder = match "multi" {
804            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("ids".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
805            _ => req_builder.query(&[("ids", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
806        };
807    }
808    if let Some(ref param_value) = p_query_credentials_identifier {
809        req_builder = req_builder.query(&[("credentials_identifier", &param_value.to_string())]);
810    }
811    if let Some(ref param_value) = p_query_preview_credentials_identifier_similar {
812        req_builder = req_builder.query(&[("preview_credentials_identifier_similar", &param_value.to_string())]);
813    }
814    if let Some(ref param_value) = p_query_include_credential {
815        req_builder = match "multi" {
816            "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)>>()),
817            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
818        };
819    }
820    if let Some(ref param_value) = p_query_organization_id {
821        req_builder = req_builder.query(&[("organization_id", &param_value.to_string())]);
822    }
823    if let Some(ref user_agent) = configuration.user_agent {
824        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
825    }
826    if let Some(ref token) = configuration.bearer_access_token {
827        req_builder = req_builder.bearer_auth(token.to_owned());
828    };
829
830    let req = req_builder.build()?;
831    let resp = configuration.client.execute(req).await?;
832
833    let status = resp.status();
834    let content_type = resp
835        .headers()
836        .get("content-type")
837        .and_then(|v| v.to_str().ok())
838        .unwrap_or("application/octet-stream");
839    let content_type = super::ContentType::from(content_type);
840
841    if !status.is_client_error() && !status.is_server_error() {
842        let content = resp.text().await?;
843        match content_type {
844            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
845            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;`"))),
846            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;`")))),
847        }
848    } else {
849        let content = resp.text().await?;
850        let entity: Option<ListIdentitiesError> = serde_json::from_str(&content).ok();
851        Err(Error::ResponseError(ResponseContent { status, content, entity }))
852    }
853}
854
855/// Returns a list of all identity schemas currently in use.
856pub 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>> {
857    // add a prefix to parameters to efficiently prevent name collisions
858    let p_query_per_page = per_page;
859    let p_query_page = page;
860    let p_query_page_size = page_size;
861    let p_query_page_token = page_token;
862
863    let uri_str = format!("{}/schemas", configuration.base_path);
864    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
865
866    if let Some(ref param_value) = p_query_per_page {
867        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
868    }
869    if let Some(ref param_value) = p_query_page {
870        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
871    }
872    if let Some(ref param_value) = p_query_page_size {
873        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
874    }
875    if let Some(ref param_value) = p_query_page_token {
876        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
877    }
878    if let Some(ref user_agent) = configuration.user_agent {
879        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
880    }
881
882    let req = req_builder.build()?;
883    let resp = configuration.client.execute(req).await?;
884
885    let status = resp.status();
886    let content_type = resp
887        .headers()
888        .get("content-type")
889        .and_then(|v| v.to_str().ok())
890        .unwrap_or("application/octet-stream");
891    let content_type = super::ContentType::from(content_type);
892
893    if !status.is_client_error() && !status.is_server_error() {
894        let content = resp.text().await?;
895        match content_type {
896            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
897            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;`"))),
898            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;`")))),
899        }
900    } else {
901        let content = resp.text().await?;
902        let entity: Option<ListIdentitySchemasError> = serde_json::from_str(&content).ok();
903        Err(Error::ResponseError(ResponseContent { status, content, entity }))
904    }
905}
906
907/// This endpoint returns all sessions that belong to the given Identity.
908pub 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>> {
909    // add a prefix to parameters to efficiently prevent name collisions
910    let p_path_id = id;
911    let p_query_per_page = per_page;
912    let p_query_page = page;
913    let p_query_page_size = page_size;
914    let p_query_page_token = page_token;
915    let p_query_active = active;
916
917    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
918    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
919
920    if let Some(ref param_value) = p_query_per_page {
921        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
922    }
923    if let Some(ref param_value) = p_query_page {
924        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
925    }
926    if let Some(ref param_value) = p_query_page_size {
927        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
928    }
929    if let Some(ref param_value) = p_query_page_token {
930        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
931    }
932    if let Some(ref param_value) = p_query_active {
933        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
934    }
935    if let Some(ref user_agent) = configuration.user_agent {
936        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
937    }
938    if let Some(ref token) = configuration.bearer_access_token {
939        req_builder = req_builder.bearer_auth(token.to_owned());
940    };
941
942    let req = req_builder.build()?;
943    let resp = configuration.client.execute(req).await?;
944
945    let status = resp.status();
946    let content_type = resp
947        .headers()
948        .get("content-type")
949        .and_then(|v| v.to_str().ok())
950        .unwrap_or("application/octet-stream");
951    let content_type = super::ContentType::from(content_type);
952
953    if !status.is_client_error() && !status.is_server_error() {
954        let content = resp.text().await?;
955        match content_type {
956            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
957            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;`"))),
958            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;`")))),
959        }
960    } else {
961        let content = resp.text().await?;
962        let entity: Option<ListIdentitySessionsError> = serde_json::from_str(&content).ok();
963        Err(Error::ResponseError(ResponseContent { status, content, entity }))
964    }
965}
966
967/// Listing all sessions that exist.
968pub 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>> {
969    // add a prefix to parameters to efficiently prevent name collisions
970    let p_query_page_size = page_size;
971    let p_query_page_token = page_token;
972    let p_query_active = active;
973    let p_query_expand = expand;
974
975    let uri_str = format!("{}/admin/sessions", configuration.base_path);
976    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
977
978    if let Some(ref param_value) = p_query_page_size {
979        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
980    }
981    if let Some(ref param_value) = p_query_page_token {
982        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
983    }
984    if let Some(ref param_value) = p_query_active {
985        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
986    }
987    if let Some(ref param_value) = p_query_expand {
988        req_builder = match "multi" {
989            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
990            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
991        };
992    }
993    if let Some(ref user_agent) = configuration.user_agent {
994        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
995    }
996    if let Some(ref token) = configuration.bearer_access_token {
997        req_builder = req_builder.bearer_auth(token.to_owned());
998    };
999
1000    let req = req_builder.build()?;
1001    let resp = configuration.client.execute(req).await?;
1002
1003    let status = resp.status();
1004    let content_type = resp
1005        .headers()
1006        .get("content-type")
1007        .and_then(|v| v.to_str().ok())
1008        .unwrap_or("application/octet-stream");
1009    let content_type = super::ContentType::from(content_type);
1010
1011    if !status.is_client_error() && !status.is_server_error() {
1012        let content = resp.text().await?;
1013        match content_type {
1014            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1015            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;`"))),
1016            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;`")))),
1017        }
1018    } else {
1019        let content = resp.text().await?;
1020        let entity: Option<ListSessionsError> = serde_json::from_str(&content).ok();
1021        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1022    }
1023}
1024
1025/// 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`.
1026pub async fn manage_sessions(configuration: &configuration::Configuration, manage_sessions_body: models::ManageSessionsBody) -> Result<models::ManageSessionsResponse, Error<ManageSessionsError>> {
1027    // add a prefix to parameters to efficiently prevent name collisions
1028    let p_body_manage_sessions_body = manage_sessions_body;
1029
1030    let uri_str = format!("{}/admin/sessions", configuration.base_path);
1031    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1032
1033    if let Some(ref user_agent) = configuration.user_agent {
1034        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1035    }
1036    if let Some(ref token) = configuration.bearer_access_token {
1037        req_builder = req_builder.bearer_auth(token.to_owned());
1038    };
1039    req_builder = req_builder.json(&p_body_manage_sessions_body);
1040
1041    let req = req_builder.build()?;
1042    let resp = configuration.client.execute(req).await?;
1043
1044    let status = resp.status();
1045    let content_type = resp
1046        .headers()
1047        .get("content-type")
1048        .and_then(|v| v.to_str().ok())
1049        .unwrap_or("application/octet-stream");
1050    let content_type = super::ContentType::from(content_type);
1051
1052    if !status.is_client_error() && !status.is_server_error() {
1053        let content = resp.text().await?;
1054        match content_type {
1055            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1056            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManageSessionsResponse`"))),
1057            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`")))),
1058        }
1059    } else {
1060        let content = resp.text().await?;
1061        let entity: Option<ManageSessionsError> = serde_json::from_str(&content).ok();
1062        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1063    }
1064}
1065
1066/// 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.
1067pub async fn patch_identity(configuration: &configuration::Configuration, id: &str, json_patch: Option<Vec<models::JsonPatch>>) -> Result<models::Identity, Error<PatchIdentityError>> {
1068    // add a prefix to parameters to efficiently prevent name collisions
1069    let p_path_id = id;
1070    let p_body_json_patch = json_patch;
1071
1072    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1073    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
1074
1075    if let Some(ref user_agent) = configuration.user_agent {
1076        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1077    }
1078    if let Some(ref token) = configuration.bearer_access_token {
1079        req_builder = req_builder.bearer_auth(token.to_owned());
1080    };
1081    req_builder = req_builder.json(&p_body_json_patch);
1082
1083    let req = req_builder.build()?;
1084    let resp = configuration.client.execute(req).await?;
1085
1086    let status = resp.status();
1087    let content_type = resp
1088        .headers()
1089        .get("content-type")
1090        .and_then(|v| v.to_str().ok())
1091        .unwrap_or("application/octet-stream");
1092    let content_type = super::ContentType::from(content_type);
1093
1094    if !status.is_client_error() && !status.is_server_error() {
1095        let content = resp.text().await?;
1096        match content_type {
1097            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1098            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1099            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`")))),
1100        }
1101    } else {
1102        let content = resp.text().await?;
1103        let entity: Option<PatchIdentityError> = serde_json::from_str(&content).ok();
1104        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1105    }
1106}
1107
1108/// 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\"}}}`).
1109pub async fn update_identity(configuration: &configuration::Configuration, id: &str, update_identity_body: Option<models::UpdateIdentityBody>) -> Result<models::Identity, Error<UpdateIdentityError>> {
1110    // add a prefix to parameters to efficiently prevent name collisions
1111    let p_path_id = id;
1112    let p_body_update_identity_body = update_identity_body;
1113
1114    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1115    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1116
1117    if let Some(ref user_agent) = configuration.user_agent {
1118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1119    }
1120    if let Some(ref token) = configuration.bearer_access_token {
1121        req_builder = req_builder.bearer_auth(token.to_owned());
1122    };
1123    req_builder = req_builder.json(&p_body_update_identity_body);
1124
1125    let req = req_builder.build()?;
1126    let resp = configuration.client.execute(req).await?;
1127
1128    let status = resp.status();
1129    let content_type = resp
1130        .headers()
1131        .get("content-type")
1132        .and_then(|v| v.to_str().ok())
1133        .unwrap_or("application/octet-stream");
1134    let content_type = super::ContentType::from(content_type);
1135
1136    if !status.is_client_error() && !status.is_server_error() {
1137        let content = resp.text().await?;
1138        match content_type {
1139            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1140            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1141            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`")))),
1142        }
1143    } else {
1144        let content = resp.text().await?;
1145        let entity: Option<UpdateIdentityError> = serde_json::from_str(&content).ok();
1146        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1147    }
1148}
1149