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.98
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.  Proxies commonly reject a slash (`/`) in a URL path even when it is percent-encoded. To look up an external ID that contains a slash, use the `external_ids` filter of the list identities endpoint instead.
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>>, external_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_external_ids = external_ids;
780    let p_query_credentials_identifier = credentials_identifier;
781    let p_query_preview_credentials_identifier_similar = preview_credentials_identifier_similar;
782    let p_query_include_credential = include_credential;
783    let p_query_organization_id = organization_id;
784
785    let uri_str = format!("{}/admin/identities", configuration.base_path);
786    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
787
788    if let Some(ref param_value) = p_query_per_page {
789        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
790    }
791    if let Some(ref param_value) = p_query_page {
792        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
793    }
794    if let Some(ref param_value) = p_query_page_size {
795        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
796    }
797    if let Some(ref param_value) = p_query_page_token {
798        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
799    }
800    if let Some(ref param_value) = p_query_consistency {
801        req_builder = req_builder.query(&[("consistency", &param_value.to_string())]);
802    }
803    if let Some(ref param_value) = p_query_ids {
804        req_builder = match "multi" {
805            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("ids".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
806            _ => req_builder.query(&[("ids", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
807        };
808    }
809    if let Some(ref param_value) = p_query_external_ids {
810        req_builder = match "multi" {
811            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("external_ids".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
812            _ => req_builder.query(&[("external_ids", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
813        };
814    }
815    if let Some(ref param_value) = p_query_credentials_identifier {
816        req_builder = req_builder.query(&[("credentials_identifier", &param_value.to_string())]);
817    }
818    if let Some(ref param_value) = p_query_preview_credentials_identifier_similar {
819        req_builder = req_builder.query(&[("preview_credentials_identifier_similar", &param_value.to_string())]);
820    }
821    if let Some(ref param_value) = p_query_include_credential {
822        req_builder = match "multi" {
823            "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)>>()),
824            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
825        };
826    }
827    if let Some(ref param_value) = p_query_organization_id {
828        req_builder = req_builder.query(&[("organization_id", &param_value.to_string())]);
829    }
830    if let Some(ref user_agent) = configuration.user_agent {
831        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
832    }
833    if let Some(ref token) = configuration.bearer_access_token {
834        req_builder = req_builder.bearer_auth(token.to_owned());
835    };
836
837    let req = req_builder.build()?;
838    let resp = configuration.client.execute(req).await?;
839
840    let status = resp.status();
841    let content_type = resp
842        .headers()
843        .get("content-type")
844        .and_then(|v| v.to_str().ok())
845        .unwrap_or("application/octet-stream");
846    let content_type = super::ContentType::from(content_type);
847
848    if !status.is_client_error() && !status.is_server_error() {
849        let content = resp.text().await?;
850        match content_type {
851            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
852            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;`"))),
853            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;`")))),
854        }
855    } else {
856        let content = resp.text().await?;
857        let entity: Option<ListIdentitiesError> = serde_json::from_str(&content).ok();
858        Err(Error::ResponseError(ResponseContent { status, content, entity }))
859    }
860}
861
862/// Returns a list of all identity schemas currently in use.
863pub 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>> {
864    // add a prefix to parameters to efficiently prevent name collisions
865    let p_query_per_page = per_page;
866    let p_query_page = page;
867    let p_query_page_size = page_size;
868    let p_query_page_token = page_token;
869
870    let uri_str = format!("{}/schemas", configuration.base_path);
871    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
872
873    if let Some(ref param_value) = p_query_per_page {
874        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
875    }
876    if let Some(ref param_value) = p_query_page {
877        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
878    }
879    if let Some(ref param_value) = p_query_page_size {
880        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
881    }
882    if let Some(ref param_value) = p_query_page_token {
883        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
884    }
885    if let Some(ref user_agent) = configuration.user_agent {
886        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
887    }
888
889    let req = req_builder.build()?;
890    let resp = configuration.client.execute(req).await?;
891
892    let status = resp.status();
893    let content_type = resp
894        .headers()
895        .get("content-type")
896        .and_then(|v| v.to_str().ok())
897        .unwrap_or("application/octet-stream");
898    let content_type = super::ContentType::from(content_type);
899
900    if !status.is_client_error() && !status.is_server_error() {
901        let content = resp.text().await?;
902        match content_type {
903            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
904            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;`"))),
905            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;`")))),
906        }
907    } else {
908        let content = resp.text().await?;
909        let entity: Option<ListIdentitySchemasError> = serde_json::from_str(&content).ok();
910        Err(Error::ResponseError(ResponseContent { status, content, entity }))
911    }
912}
913
914/// This endpoint returns all sessions that belong to the given Identity.
915pub 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>> {
916    // add a prefix to parameters to efficiently prevent name collisions
917    let p_path_id = id;
918    let p_query_per_page = per_page;
919    let p_query_page = page;
920    let p_query_page_size = page_size;
921    let p_query_page_token = page_token;
922    let p_query_active = active;
923
924    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
925    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
926
927    if let Some(ref param_value) = p_query_per_page {
928        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
929    }
930    if let Some(ref param_value) = p_query_page {
931        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
932    }
933    if let Some(ref param_value) = p_query_page_size {
934        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
935    }
936    if let Some(ref param_value) = p_query_page_token {
937        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
938    }
939    if let Some(ref param_value) = p_query_active {
940        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
941    }
942    if let Some(ref user_agent) = configuration.user_agent {
943        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
944    }
945    if let Some(ref token) = configuration.bearer_access_token {
946        req_builder = req_builder.bearer_auth(token.to_owned());
947    };
948
949    let req = req_builder.build()?;
950    let resp = configuration.client.execute(req).await?;
951
952    let status = resp.status();
953    let content_type = resp
954        .headers()
955        .get("content-type")
956        .and_then(|v| v.to_str().ok())
957        .unwrap_or("application/octet-stream");
958    let content_type = super::ContentType::from(content_type);
959
960    if !status.is_client_error() && !status.is_server_error() {
961        let content = resp.text().await?;
962        match content_type {
963            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
964            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;`"))),
965            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;`")))),
966        }
967    } else {
968        let content = resp.text().await?;
969        let entity: Option<ListIdentitySessionsError> = serde_json::from_str(&content).ok();
970        Err(Error::ResponseError(ResponseContent { status, content, entity }))
971    }
972}
973
974/// Listing all sessions that exist.
975pub 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>> {
976    // add a prefix to parameters to efficiently prevent name collisions
977    let p_query_page_size = page_size;
978    let p_query_page_token = page_token;
979    let p_query_active = active;
980    let p_query_expand = expand;
981
982    let uri_str = format!("{}/admin/sessions", configuration.base_path);
983    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
984
985    if let Some(ref param_value) = p_query_page_size {
986        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
987    }
988    if let Some(ref param_value) = p_query_page_token {
989        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
990    }
991    if let Some(ref param_value) = p_query_active {
992        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
993    }
994    if let Some(ref param_value) = p_query_expand {
995        req_builder = match "multi" {
996            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
997            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
998        };
999    }
1000    if let Some(ref user_agent) = configuration.user_agent {
1001        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1002    }
1003    if let Some(ref token) = configuration.bearer_access_token {
1004        req_builder = req_builder.bearer_auth(token.to_owned());
1005    };
1006
1007    let req = req_builder.build()?;
1008    let resp = configuration.client.execute(req).await?;
1009
1010    let status = resp.status();
1011    let content_type = resp
1012        .headers()
1013        .get("content-type")
1014        .and_then(|v| v.to_str().ok())
1015        .unwrap_or("application/octet-stream");
1016    let content_type = super::ContentType::from(content_type);
1017
1018    if !status.is_client_error() && !status.is_server_error() {
1019        let content = resp.text().await?;
1020        match content_type {
1021            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1022            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;`"))),
1023            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;`")))),
1024        }
1025    } else {
1026        let content = resp.text().await?;
1027        let entity: Option<ListSessionsError> = serde_json::from_str(&content).ok();
1028        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1029    }
1030}
1031
1032/// 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`.
1033pub async fn manage_sessions(configuration: &configuration::Configuration, manage_sessions_body: models::ManageSessionsBody) -> Result<models::ManageSessionsResponse, Error<ManageSessionsError>> {
1034    // add a prefix to parameters to efficiently prevent name collisions
1035    let p_body_manage_sessions_body = manage_sessions_body;
1036
1037    let uri_str = format!("{}/admin/sessions", configuration.base_path);
1038    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
1039
1040    if let Some(ref user_agent) = configuration.user_agent {
1041        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1042    }
1043    if let Some(ref token) = configuration.bearer_access_token {
1044        req_builder = req_builder.bearer_auth(token.to_owned());
1045    };
1046    req_builder = req_builder.json(&p_body_manage_sessions_body);
1047
1048    let req = req_builder.build()?;
1049    let resp = configuration.client.execute(req).await?;
1050
1051    let status = resp.status();
1052    let content_type = resp
1053        .headers()
1054        .get("content-type")
1055        .and_then(|v| v.to_str().ok())
1056        .unwrap_or("application/octet-stream");
1057    let content_type = super::ContentType::from(content_type);
1058
1059    if !status.is_client_error() && !status.is_server_error() {
1060        let content = resp.text().await?;
1061        match content_type {
1062            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1063            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManageSessionsResponse`"))),
1064            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`")))),
1065        }
1066    } else {
1067        let content = resp.text().await?;
1068        let entity: Option<ManageSessionsError> = serde_json::from_str(&content).ok();
1069        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1070    }
1071}
1072
1073/// 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.
1074pub async fn patch_identity(configuration: &configuration::Configuration, id: &str, json_patch: Option<Vec<models::JsonPatch>>) -> Result<models::Identity, Error<PatchIdentityError>> {
1075    // add a prefix to parameters to efficiently prevent name collisions
1076    let p_path_id = id;
1077    let p_body_json_patch = json_patch;
1078
1079    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1080    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
1081
1082    if let Some(ref user_agent) = configuration.user_agent {
1083        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1084    }
1085    if let Some(ref token) = configuration.bearer_access_token {
1086        req_builder = req_builder.bearer_auth(token.to_owned());
1087    };
1088    req_builder = req_builder.json(&p_body_json_patch);
1089
1090    let req = req_builder.build()?;
1091    let resp = configuration.client.execute(req).await?;
1092
1093    let status = resp.status();
1094    let content_type = resp
1095        .headers()
1096        .get("content-type")
1097        .and_then(|v| v.to_str().ok())
1098        .unwrap_or("application/octet-stream");
1099    let content_type = super::ContentType::from(content_type);
1100
1101    if !status.is_client_error() && !status.is_server_error() {
1102        let content = resp.text().await?;
1103        match content_type {
1104            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1105            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1106            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`")))),
1107        }
1108    } else {
1109        let content = resp.text().await?;
1110        let entity: Option<PatchIdentityError> = serde_json::from_str(&content).ok();
1111        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1112    }
1113}
1114
1115/// 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\"}}}`).
1116pub async fn update_identity(configuration: &configuration::Configuration, id: &str, update_identity_body: Option<models::UpdateIdentityBody>) -> Result<models::Identity, Error<UpdateIdentityError>> {
1117    // add a prefix to parameters to efficiently prevent name collisions
1118    let p_path_id = id;
1119    let p_body_update_identity_body = update_identity_body;
1120
1121    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1122    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1123
1124    if let Some(ref user_agent) = configuration.user_agent {
1125        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1126    }
1127    if let Some(ref token) = configuration.bearer_access_token {
1128        req_builder = req_builder.bearer_auth(token.to_owned());
1129    };
1130    req_builder = req_builder.json(&p_body_update_identity_body);
1131
1132    let req = req_builder.build()?;
1133    let resp = configuration.client.execute(req).await?;
1134
1135    let status = resp.status();
1136    let content_type = resp
1137        .headers()
1138        .get("content-type")
1139        .and_then(|v| v.to_str().ok())
1140        .unwrap_or("application/octet-stream");
1141    let content_type = super::ContentType::from(content_type);
1142
1143    if !status.is_client_error() && !status.is_server_error() {
1144        let content = resp.text().await?;
1145        match content_type {
1146            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1147            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1148            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`")))),
1149        }
1150    } else {
1151        let content = resp.text().await?;
1152        let entity: Option<UpdateIdentityError> = serde_json::from_str(&content).ok();
1153        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1154    }
1155}
1156