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.17.2
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
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 [`delete_identity`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum DeleteIdentityError {
62    Status404(models::ErrorGeneric),
63    DefaultResponse(models::ErrorGeneric),
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`delete_identity_credentials`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum DeleteIdentityCredentialsError {
71    Status404(models::ErrorGeneric),
72    DefaultResponse(models::ErrorGeneric),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`delete_identity_sessions`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum DeleteIdentitySessionsError {
80    Status400(models::ErrorGeneric),
81    Status401(models::ErrorGeneric),
82    Status404(models::ErrorGeneric),
83    DefaultResponse(models::ErrorGeneric),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`disable_session`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum DisableSessionError {
91    Status400(models::ErrorGeneric),
92    Status401(models::ErrorGeneric),
93    DefaultResponse(models::ErrorGeneric),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`extend_session`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum ExtendSessionError {
101    Status400(models::ErrorGeneric),
102    Status404(models::ErrorGeneric),
103    DefaultResponse(models::ErrorGeneric),
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`get_identity`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetIdentityError {
111    Status404(models::ErrorGeneric),
112    DefaultResponse(models::ErrorGeneric),
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`get_identity_schema`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum GetIdentitySchemaError {
120    Status404(models::ErrorGeneric),
121    DefaultResponse(models::ErrorGeneric),
122    UnknownValue(serde_json::Value),
123}
124
125/// struct for typed errors of method [`get_session`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum GetSessionError {
129    Status400(models::ErrorGeneric),
130    DefaultResponse(models::ErrorGeneric),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`list_identities`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum ListIdentitiesError {
138    DefaultResponse(models::ErrorGeneric),
139    UnknownValue(serde_json::Value),
140}
141
142/// struct for typed errors of method [`list_identity_schemas`]
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum ListIdentitySchemasError {
146    DefaultResponse(models::ErrorGeneric),
147    UnknownValue(serde_json::Value),
148}
149
150/// struct for typed errors of method [`list_identity_sessions`]
151#[derive(Debug, Clone, Serialize, Deserialize)]
152#[serde(untagged)]
153pub enum ListIdentitySessionsError {
154    Status400(models::ErrorGeneric),
155    Status404(models::ErrorGeneric),
156    DefaultResponse(models::ErrorGeneric),
157    UnknownValue(serde_json::Value),
158}
159
160/// struct for typed errors of method [`list_sessions`]
161#[derive(Debug, Clone, Serialize, Deserialize)]
162#[serde(untagged)]
163pub enum ListSessionsError {
164    Status400(models::ErrorGeneric),
165    DefaultResponse(models::ErrorGeneric),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`patch_identity`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum PatchIdentityError {
173    Status400(models::ErrorGeneric),
174    Status404(models::ErrorGeneric),
175    Status409(models::ErrorGeneric),
176    DefaultResponse(models::ErrorGeneric),
177    UnknownValue(serde_json::Value),
178}
179
180/// struct for typed errors of method [`update_identity`]
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum UpdateIdentityError {
184    Status400(models::ErrorGeneric),
185    Status404(models::ErrorGeneric),
186    Status409(models::ErrorGeneric),
187    DefaultResponse(models::ErrorGeneric),
188    UnknownValue(serde_json::Value),
189}
190
191
192/// Creates multiple [identities](https://www.ory.sh/docs/kratos/concepts/identity-user-model). This endpoint can also be used to [import credentials](https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities) for instance passwords, social sign in configurations or multifactor methods.
193pub async fn batch_patch_identities(configuration: &configuration::Configuration, patch_identities_body: Option<models::PatchIdentitiesBody>) -> Result<models::BatchPatchIdentitiesResponse, Error<BatchPatchIdentitiesError>> {
194    let local_var_configuration = configuration;
195
196    let local_var_client = &local_var_configuration.client;
197
198    let local_var_uri_str = format!("{}/admin/identities", local_var_configuration.base_path);
199    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
200
201    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
202        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203    }
204    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
205        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
206    };
207    local_var_req_builder = local_var_req_builder.json(&patch_identities_body);
208
209    let local_var_req = local_var_req_builder.build()?;
210    let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212    let local_var_status = local_var_resp.status();
213    let local_var_content = local_var_resp.text().await?;
214
215    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
216        serde_json::from_str(&local_var_content).map_err(Error::from)
217    } else {
218        let local_var_entity: Option<BatchPatchIdentitiesError> = serde_json::from_str(&local_var_content).ok();
219        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
220        Err(Error::ResponseError(local_var_error))
221    }
222}
223
224/// Create an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model).  This endpoint can also be used to [import credentials](https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities) for instance passwords, social sign in configurations or multifactor methods.
225pub async fn create_identity(configuration: &configuration::Configuration, create_identity_body: Option<models::CreateIdentityBody>) -> Result<models::Identity, Error<CreateIdentityError>> {
226    let local_var_configuration = configuration;
227
228    let local_var_client = &local_var_configuration.client;
229
230    let local_var_uri_str = format!("{}/admin/identities", local_var_configuration.base_path);
231    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
232
233    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
234        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
235    }
236    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
237        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
238    };
239    local_var_req_builder = local_var_req_builder.json(&create_identity_body);
240
241    let local_var_req = local_var_req_builder.build()?;
242    let local_var_resp = local_var_client.execute(local_var_req).await?;
243
244    let local_var_status = local_var_resp.status();
245    let local_var_content = local_var_resp.text().await?;
246
247    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
248        serde_json::from_str(&local_var_content).map_err(Error::from)
249    } else {
250        let local_var_entity: Option<CreateIdentityError> = serde_json::from_str(&local_var_content).ok();
251        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
252        Err(Error::ResponseError(local_var_error))
253    }
254}
255
256/// This endpoint creates a recovery code which should be given to the user in order for them to recover (or activate) their account.
257pub async fn create_recovery_code_for_identity(configuration: &configuration::Configuration, create_recovery_code_for_identity_body: Option<models::CreateRecoveryCodeForIdentityBody>) -> Result<models::RecoveryCodeForIdentity, Error<CreateRecoveryCodeForIdentityError>> {
258    let local_var_configuration = configuration;
259
260    let local_var_client = &local_var_configuration.client;
261
262    let local_var_uri_str = format!("{}/admin/recovery/code", local_var_configuration.base_path);
263    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
264
265    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
267    }
268    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
269        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
270    };
271    local_var_req_builder = local_var_req_builder.json(&create_recovery_code_for_identity_body);
272
273    let local_var_req = local_var_req_builder.build()?;
274    let local_var_resp = local_var_client.execute(local_var_req).await?;
275
276    let local_var_status = local_var_resp.status();
277    let local_var_content = local_var_resp.text().await?;
278
279    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
280        serde_json::from_str(&local_var_content).map_err(Error::from)
281    } else {
282        let local_var_entity: Option<CreateRecoveryCodeForIdentityError> = serde_json::from_str(&local_var_content).ok();
283        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
284        Err(Error::ResponseError(local_var_error))
285    }
286}
287
288/// This endpoint creates a recovery link which should be given to the user in order for them to recover (or activate) their account.
289pub 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>> {
290    let local_var_configuration = configuration;
291
292    let local_var_client = &local_var_configuration.client;
293
294    let local_var_uri_str = format!("{}/admin/recovery/link", local_var_configuration.base_path);
295    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
296
297    if let Some(ref local_var_str) = return_to {
298        local_var_req_builder = local_var_req_builder.query(&[("return_to", &local_var_str.to_string())]);
299    }
300    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
301        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
302    }
303    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
304        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
305    };
306    local_var_req_builder = local_var_req_builder.json(&create_recovery_link_for_identity_body);
307
308    let local_var_req = local_var_req_builder.build()?;
309    let local_var_resp = local_var_client.execute(local_var_req).await?;
310
311    let local_var_status = local_var_resp.status();
312    let local_var_content = local_var_resp.text().await?;
313
314    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315        serde_json::from_str(&local_var_content).map_err(Error::from)
316    } else {
317        let local_var_entity: Option<CreateRecoveryLinkForIdentityError> = serde_json::from_str(&local_var_content).ok();
318        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
319        Err(Error::ResponseError(local_var_error))
320    }
321}
322
323/// Calling this endpoint irrecoverably and permanently deletes the [identity](https://www.ory.sh/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 when the identity was not found, in which case it is assumed that is has been deleted already.
324pub async fn delete_identity(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentityError>> {
325    let local_var_configuration = configuration;
326
327    let local_var_client = &local_var_configuration.client;
328
329    let local_var_uri_str = format!("{}/admin/identities/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
330    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
331
332    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
333        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
334    }
335    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
336        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
337    };
338
339    let local_var_req = local_var_req_builder.build()?;
340    let local_var_resp = local_var_client.execute(local_var_req).await?;
341
342    let local_var_status = local_var_resp.status();
343    let local_var_content = local_var_resp.text().await?;
344
345    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
346        Ok(())
347    } else {
348        let local_var_entity: Option<DeleteIdentityError> = serde_json::from_str(&local_var_content).ok();
349        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
350        Err(Error::ResponseError(local_var_error))
351    }
352}
353
354/// Delete an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) credential by its type. You cannot delete password or code auth credentials through this API.
355pub async fn delete_identity_credentials(configuration: &configuration::Configuration, id: &str, r#type: &str, identifier: Option<&str>) -> Result<(), Error<DeleteIdentityCredentialsError>> {
356    let local_var_configuration = configuration;
357
358    let local_var_client = &local_var_configuration.client;
359
360    let local_var_uri_str = format!("{}/admin/identities/{id}/credentials/{type}", local_var_configuration.base_path, id=crate::apis::urlencode(id), type=crate::apis::urlencode(r#type));
361    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
362
363    if let Some(ref local_var_str) = identifier {
364        local_var_req_builder = local_var_req_builder.query(&[("identifier", &local_var_str.to_string())]);
365    }
366    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
367        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
368    }
369    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
370        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
371    };
372
373    let local_var_req = local_var_req_builder.build()?;
374    let local_var_resp = local_var_client.execute(local_var_req).await?;
375
376    let local_var_status = local_var_resp.status();
377    let local_var_content = local_var_resp.text().await?;
378
379    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
380        Ok(())
381    } else {
382        let local_var_entity: Option<DeleteIdentityCredentialsError> = serde_json::from_str(&local_var_content).ok();
383        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
384        Err(Error::ResponseError(local_var_error))
385    }
386}
387
388/// Calling this endpoint irrecoverably and permanently deletes and invalidates all sessions that belong to the given Identity.
389pub async fn delete_identity_sessions(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentitySessionsError>> {
390    let local_var_configuration = configuration;
391
392    let local_var_client = &local_var_configuration.client;
393
394    let local_var_uri_str = format!("{}/admin/identities/{id}/sessions", local_var_configuration.base_path, id=crate::apis::urlencode(id));
395    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
396
397    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
398        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
399    }
400    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
401        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
402    };
403
404    let local_var_req = local_var_req_builder.build()?;
405    let local_var_resp = local_var_client.execute(local_var_req).await?;
406
407    let local_var_status = local_var_resp.status();
408    let local_var_content = local_var_resp.text().await?;
409
410    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
411        Ok(())
412    } else {
413        let local_var_entity: Option<DeleteIdentitySessionsError> = serde_json::from_str(&local_var_content).ok();
414        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
415        Err(Error::ResponseError(local_var_error))
416    }
417}
418
419/// Calling this endpoint deactivates the specified session. Session data is not deleted.
420pub async fn disable_session(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DisableSessionError>> {
421    let local_var_configuration = configuration;
422
423    let local_var_client = &local_var_configuration.client;
424
425    let local_var_uri_str = format!("{}/admin/sessions/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
426    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
427
428    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
429        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
430    }
431    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
432        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
433    };
434
435    let local_var_req = local_var_req_builder.build()?;
436    let local_var_resp = local_var_client.execute(local_var_req).await?;
437
438    let local_var_status = local_var_resp.status();
439    let local_var_content = local_var_resp.text().await?;
440
441    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
442        Ok(())
443    } else {
444        let local_var_entity: Option<DisableSessionError> = serde_json::from_str(&local_var_content).ok();
445        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
446        Err(Error::ResponseError(local_var_error))
447    }
448}
449
450/// Calling this endpoint extends the given session ID. If `session.earliest_possible_extend` is set it will only extend the session after the specified time has passed.  This endpoint returns per default a 204 No Content response on success. Older Ory Network projects may return a 200 OK response with the session in the body. Returning the session as part of the response will be deprecated in the future and should not be relied upon.  This endpoint ignores consecutive requests to extend the same session and returns a 404 error in those scenarios. This endpoint also returns 404 errors if the session does not exist.  Retrieve the session ID from the `/sessions/whoami` endpoint / `toSession` SDK method.
451pub async fn extend_session(configuration: &configuration::Configuration, id: &str) -> Result<models::Session, Error<ExtendSessionError>> {
452    let local_var_configuration = configuration;
453
454    let local_var_client = &local_var_configuration.client;
455
456    let local_var_uri_str = format!("{}/admin/sessions/{id}/extend", local_var_configuration.base_path, id=crate::apis::urlencode(id));
457    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
458
459    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
460        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
461    }
462    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
463        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
464    };
465
466    let local_var_req = local_var_req_builder.build()?;
467    let local_var_resp = local_var_client.execute(local_var_req).await?;
468
469    let local_var_status = local_var_resp.status();
470    let local_var_content = local_var_resp.text().await?;
471
472    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
473        serde_json::from_str(&local_var_content).map_err(Error::from)
474    } else {
475        let local_var_entity: Option<ExtendSessionError> = serde_json::from_str(&local_var_content).ok();
476        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
477        Err(Error::ResponseError(local_var_error))
478    }
479}
480
481/// Return an [identity](https://www.ory.sh/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.
482pub async fn get_identity(configuration: &configuration::Configuration, id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityError>> {
483    let local_var_configuration = configuration;
484
485    let local_var_client = &local_var_configuration.client;
486
487    let local_var_uri_str = format!("{}/admin/identities/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
488    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
489
490    if let Some(ref local_var_str) = include_credential {
491        local_var_req_builder = match "multi" {
492            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
493            _ => local_var_req_builder.query(&[("include_credential", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
494        };
495    }
496    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
497        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
498    }
499    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
500        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
501    };
502
503    let local_var_req = local_var_req_builder.build()?;
504    let local_var_resp = local_var_client.execute(local_var_req).await?;
505
506    let local_var_status = local_var_resp.status();
507    let local_var_content = local_var_resp.text().await?;
508
509    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
510        serde_json::from_str(&local_var_content).map_err(Error::from)
511    } else {
512        let local_var_entity: Option<GetIdentityError> = serde_json::from_str(&local_var_content).ok();
513        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
514        Err(Error::ResponseError(local_var_error))
515    }
516}
517
518/// Return a specific identity schema.
519pub async fn get_identity_schema(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<GetIdentitySchemaError>> {
520    let local_var_configuration = configuration;
521
522    let local_var_client = &local_var_configuration.client;
523
524    let local_var_uri_str = format!("{}/schemas/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
525    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
526
527    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
528        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
529    }
530
531    let local_var_req = local_var_req_builder.build()?;
532    let local_var_resp = local_var_client.execute(local_var_req).await?;
533
534    let local_var_status = local_var_resp.status();
535    let local_var_content = local_var_resp.text().await?;
536
537    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
538        serde_json::from_str(&local_var_content).map_err(Error::from)
539    } else {
540        let local_var_entity: Option<GetIdentitySchemaError> = serde_json::from_str(&local_var_content).ok();
541        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
542        Err(Error::ResponseError(local_var_error))
543    }
544}
545
546/// This endpoint is useful for:  Getting a session object with all specified expandables that exist in an administrative context.
547pub async fn get_session(configuration: &configuration::Configuration, id: &str, expand: Option<Vec<String>>) -> Result<models::Session, Error<GetSessionError>> {
548    let local_var_configuration = configuration;
549
550    let local_var_client = &local_var_configuration.client;
551
552    let local_var_uri_str = format!("{}/admin/sessions/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
553    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
554
555    if let Some(ref local_var_str) = expand {
556        local_var_req_builder = match "multi" {
557            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
558            _ => local_var_req_builder.query(&[("expand", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
559        };
560    }
561    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
562        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
563    }
564    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
565        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
566    };
567
568    let local_var_req = local_var_req_builder.build()?;
569    let local_var_resp = local_var_client.execute(local_var_req).await?;
570
571    let local_var_status = local_var_resp.status();
572    let local_var_content = local_var_resp.text().await?;
573
574    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
575        serde_json::from_str(&local_var_content).map_err(Error::from)
576    } else {
577        let local_var_entity: Option<GetSessionError> = serde_json::from_str(&local_var_content).ok();
578        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
579        Err(Error::ResponseError(local_var_error))
580    }
581}
582
583/// Lists all [identities](https://www.ory.sh/docs/kratos/concepts/identity-user-model) in the system. Note: filters cannot be combined.
584pub 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>> {
585    let local_var_configuration = configuration;
586
587    let local_var_client = &local_var_configuration.client;
588
589    let local_var_uri_str = format!("{}/admin/identities", local_var_configuration.base_path);
590    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
591
592    if let Some(ref local_var_str) = per_page {
593        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
594    }
595    if let Some(ref local_var_str) = page {
596        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
597    }
598    if let Some(ref local_var_str) = page_size {
599        local_var_req_builder = local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
600    }
601    if let Some(ref local_var_str) = page_token {
602        local_var_req_builder = local_var_req_builder.query(&[("page_token", &local_var_str.to_string())]);
603    }
604    if let Some(ref local_var_str) = consistency {
605        local_var_req_builder = local_var_req_builder.query(&[("consistency", &local_var_str.to_string())]);
606    }
607    if let Some(ref local_var_str) = ids {
608        local_var_req_builder = match "multi" {
609            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("ids".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
610            _ => local_var_req_builder.query(&[("ids", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
611        };
612    }
613    if let Some(ref local_var_str) = credentials_identifier {
614        local_var_req_builder = local_var_req_builder.query(&[("credentials_identifier", &local_var_str.to_string())]);
615    }
616    if let Some(ref local_var_str) = preview_credentials_identifier_similar {
617        local_var_req_builder = local_var_req_builder.query(&[("preview_credentials_identifier_similar", &local_var_str.to_string())]);
618    }
619    if let Some(ref local_var_str) = include_credential {
620        local_var_req_builder = match "multi" {
621            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
622            _ => local_var_req_builder.query(&[("include_credential", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
623        };
624    }
625    if let Some(ref local_var_str) = organization_id {
626        local_var_req_builder = local_var_req_builder.query(&[("organization_id", &local_var_str.to_string())]);
627    }
628    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
629        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
630    }
631    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
632        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
633    };
634
635    let local_var_req = local_var_req_builder.build()?;
636    let local_var_resp = local_var_client.execute(local_var_req).await?;
637
638    let local_var_status = local_var_resp.status();
639    let local_var_content = local_var_resp.text().await?;
640
641    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
642        serde_json::from_str(&local_var_content).map_err(Error::from)
643    } else {
644        let local_var_entity: Option<ListIdentitiesError> = serde_json::from_str(&local_var_content).ok();
645        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
646        Err(Error::ResponseError(local_var_error))
647    }
648}
649
650/// Returns a list of all identity schemas currently in use.
651pub 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>> {
652    let local_var_configuration = configuration;
653
654    let local_var_client = &local_var_configuration.client;
655
656    let local_var_uri_str = format!("{}/schemas", local_var_configuration.base_path);
657    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
658
659    if let Some(ref local_var_str) = per_page {
660        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
661    }
662    if let Some(ref local_var_str) = page {
663        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
664    }
665    if let Some(ref local_var_str) = page_size {
666        local_var_req_builder = local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
667    }
668    if let Some(ref local_var_str) = page_token {
669        local_var_req_builder = local_var_req_builder.query(&[("page_token", &local_var_str.to_string())]);
670    }
671    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
672        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
673    }
674
675    let local_var_req = local_var_req_builder.build()?;
676    let local_var_resp = local_var_client.execute(local_var_req).await?;
677
678    let local_var_status = local_var_resp.status();
679    let local_var_content = local_var_resp.text().await?;
680
681    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
682        serde_json::from_str(&local_var_content).map_err(Error::from)
683    } else {
684        let local_var_entity: Option<ListIdentitySchemasError> = serde_json::from_str(&local_var_content).ok();
685        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
686        Err(Error::ResponseError(local_var_error))
687    }
688}
689
690/// This endpoint returns all sessions that belong to the given Identity.
691pub 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>> {
692    let local_var_configuration = configuration;
693
694    let local_var_client = &local_var_configuration.client;
695
696    let local_var_uri_str = format!("{}/admin/identities/{id}/sessions", local_var_configuration.base_path, id=crate::apis::urlencode(id));
697    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
698
699    if let Some(ref local_var_str) = per_page {
700        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
701    }
702    if let Some(ref local_var_str) = page {
703        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
704    }
705    if let Some(ref local_var_str) = page_size {
706        local_var_req_builder = local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
707    }
708    if let Some(ref local_var_str) = page_token {
709        local_var_req_builder = local_var_req_builder.query(&[("page_token", &local_var_str.to_string())]);
710    }
711    if let Some(ref local_var_str) = active {
712        local_var_req_builder = local_var_req_builder.query(&[("active", &local_var_str.to_string())]);
713    }
714    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
715        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
716    }
717    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
718        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
719    };
720
721    let local_var_req = local_var_req_builder.build()?;
722    let local_var_resp = local_var_client.execute(local_var_req).await?;
723
724    let local_var_status = local_var_resp.status();
725    let local_var_content = local_var_resp.text().await?;
726
727    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
728        serde_json::from_str(&local_var_content).map_err(Error::from)
729    } else {
730        let local_var_entity: Option<ListIdentitySessionsError> = serde_json::from_str(&local_var_content).ok();
731        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
732        Err(Error::ResponseError(local_var_error))
733    }
734}
735
736/// Listing all sessions that exist.
737pub 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>> {
738    let local_var_configuration = configuration;
739
740    let local_var_client = &local_var_configuration.client;
741
742    let local_var_uri_str = format!("{}/admin/sessions", local_var_configuration.base_path);
743    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
744
745    if let Some(ref local_var_str) = page_size {
746        local_var_req_builder = local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
747    }
748    if let Some(ref local_var_str) = page_token {
749        local_var_req_builder = local_var_req_builder.query(&[("page_token", &local_var_str.to_string())]);
750    }
751    if let Some(ref local_var_str) = active {
752        local_var_req_builder = local_var_req_builder.query(&[("active", &local_var_str.to_string())]);
753    }
754    if let Some(ref local_var_str) = expand {
755        local_var_req_builder = match "multi" {
756            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
757            _ => local_var_req_builder.query(&[("expand", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
758        };
759    }
760    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
761        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
762    }
763    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
764        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
765    };
766
767    let local_var_req = local_var_req_builder.build()?;
768    let local_var_resp = local_var_client.execute(local_var_req).await?;
769
770    let local_var_status = local_var_resp.status();
771    let local_var_content = local_var_resp.text().await?;
772
773    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
774        serde_json::from_str(&local_var_content).map_err(Error::from)
775    } else {
776        let local_var_entity: Option<ListSessionsError> = serde_json::from_str(&local_var_content).ok();
777        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
778        Err(Error::ResponseError(local_var_error))
779    }
780}
781
782/// Partially updates an [identity's](https://www.ory.sh/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.
783pub async fn patch_identity(configuration: &configuration::Configuration, id: &str, json_patch: Option<Vec<models::JsonPatch>>) -> Result<models::Identity, Error<PatchIdentityError>> {
784    let local_var_configuration = configuration;
785
786    let local_var_client = &local_var_configuration.client;
787
788    let local_var_uri_str = format!("{}/admin/identities/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
789    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
790
791    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
792        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
793    }
794    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
795        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
796    };
797    local_var_req_builder = local_var_req_builder.json(&json_patch);
798
799    let local_var_req = local_var_req_builder.build()?;
800    let local_var_resp = local_var_client.execute(local_var_req).await?;
801
802    let local_var_status = local_var_resp.status();
803    let local_var_content = local_var_resp.text().await?;
804
805    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
806        serde_json::from_str(&local_var_content).map_err(Error::from)
807    } else {
808        let local_var_entity: Option<PatchIdentityError> = serde_json::from_str(&local_var_content).ok();
809        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
810        Err(Error::ResponseError(local_var_error))
811    }
812}
813
814/// This endpoint updates an [identity](https://www.ory.sh/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.
815pub async fn update_identity(configuration: &configuration::Configuration, id: &str, update_identity_body: Option<models::UpdateIdentityBody>) -> Result<models::Identity, Error<UpdateIdentityError>> {
816    let local_var_configuration = configuration;
817
818    let local_var_client = &local_var_configuration.client;
819
820    let local_var_uri_str = format!("{}/admin/identities/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
821    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
822
823    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
824        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
825    }
826    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
827        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
828    };
829    local_var_req_builder = local_var_req_builder.json(&update_identity_body);
830
831    let local_var_req = local_var_req_builder.build()?;
832    let local_var_resp = local_var_client.execute(local_var_req).await?;
833
834    let local_var_status = local_var_resp.status();
835    let local_var_content = local_var_resp.text().await?;
836
837    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
838        serde_json::from_str(&local_var_content).map_err(Error::from)
839    } else {
840        let local_var_entity: Option<UpdateIdentityError> = serde_json::from_str(&local_var_content).ok();
841        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
842        Err(Error::ResponseError(local_var_error))
843    }
844}
845