clerk_fapi_rs/apis/
sign_ins_api.rs

1/*
2 * Clerk Frontend API
3 *
4 * The Clerk REST Frontend API, meant to be accessed from a browser or native environment.  This is a Form Based API and all the data must be sent and formatted according to the `application/x-www-form-urlencoded` content type.  ### Versions  When the API changes in a way that isn't compatible with older versions, a new version is released. Each version is identified by its release date, e.g. `2021-02-05`. For more information, please see [Clerk API Versions](https://clerk.com/docs/backend-requests/versioning/overview).  ### Using the Try It Console  The `Try It` feature of the docs only works for **Development Instances** when using the `DevBrowser` security scheme. To use it, first generate a dev instance token from the `/v1/dev_browser` endpoint.  Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`accept_ticket`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AcceptTicketError {
20    Status400(models::ClerkErrors),
21    Status404(models::ClerkErrors),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`attempt_sign_in_factor_one`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AttemptSignInFactorOneError {
29    Status400(models::ClerkErrors),
30    Status403(models::ClerkErrors),
31    Status404(models::ClerkErrors),
32    Status422(models::ClerkErrors),
33    Status429(models::ClerkErrors),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`attempt_sign_in_factor_two`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum AttemptSignInFactorTwoError {
41    Status400(models::ClerkErrors),
42    Status403(models::ClerkErrors),
43    Status422(models::ClerkErrors),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`create_sign_in`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum CreateSignInError {
51    Status400(models::ClerkErrors),
52    Status403(models::ClerkErrors),
53    Status404(models::ClerkErrors),
54    Status409(models::ClerkErrors),
55    Status422(models::ClerkErrors),
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`get_sign_in`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum GetSignInError {
63    Status400(models::ClerkErrors),
64    Status401(models::ClerkErrors),
65    Status404(models::ClerkErrors),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`prepare_sign_in_factor_one`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum PrepareSignInFactorOneError {
73    Status400(models::ClerkErrors),
74    Status403(models::ClerkErrors),
75    Status404(models::ClerkErrors),
76    Status422(models::ClerkErrors),
77    Status429(models::ClerkErrors),
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`prepare_sign_in_factor_two`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum PrepareSignInFactorTwoError {
85    Status400(models::ClerkErrors),
86    Status403(models::ClerkErrors),
87    Status422(models::ClerkErrors),
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`reset_password`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum ResetPasswordError {
95    Status400(models::ClerkErrors),
96    Status422(models::ClerkErrors),
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`verify`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum VerifyError {
104    Status400(models::ClerkErrors),
105    UnknownValue(serde_json::Value),
106}
107
108/// Parses a ticket JWT and performs the necessary actions depending on the ticket's source type. Depending on the ticket source type, a successful response can either redirect to a new location with the ticket in the query string, or respond directly with a text/html content type for the response body.
109pub async fn accept_ticket(
110    configuration: &configuration::Configuration,
111    ticket: &str,
112) -> Result<(), Error<AcceptTicketError>> {
113    // add a prefix to parameters to efficiently prevent name collisions
114    let p_query_ticket = ticket;
115
116    let uri_str = format!("{}/v1/tickets/accept", configuration.base_path);
117    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
118
119    req_builder = req_builder.query(&[("ticket", &p_query_ticket.to_string())]);
120    if let Some(ref apikey) = configuration.api_key {
121        let key = apikey.key.clone();
122        let value = match apikey.prefix {
123            Some(ref prefix) => format!("{prefix} {key}"),
124            None => key,
125        };
126        req_builder = req_builder.query(&[("__dev_session", value)]);
127    }
128    if let Some(ref user_agent) = configuration.user_agent {
129        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130    }
131    if let Some(ref apikey) = configuration.api_key {
132        let key = apikey.key.clone();
133        let value = match apikey.prefix {
134            Some(ref prefix) => format!("{prefix} {key}"),
135            None => key,
136        };
137        req_builder = req_builder.header("__session", value);
138    };
139
140    let req = req_builder.build()?;
141    let resp = configuration.client.execute(req).await?;
142
143    let status = resp.status();
144
145    if !status.is_client_error() && !status.is_server_error() {
146        Ok(())
147    } else {
148        let content = resp.text().await?;
149        let entity: Option<AcceptTicketError> = serde_json::from_str(&content).ok();
150        Err(Error::ResponseError(ResponseContent {
151            status,
152            content,
153            entity,
154        }))
155    }
156}
157
158/// Attempt the first verification. Requires the sign in attempt to be identified, and the first factor verification to be prepared, unless you're using a password.  Parameter rules: If the strategy equals `email_code` or `phone_code` then a code is required. If the strategy equals `password` then a password is required.
159pub async fn attempt_sign_in_factor_one(
160    configuration: &configuration::Configuration,
161    sign_in_id: &str,
162    strategy: &str,
163    origin: Option<&str>,
164    code: Option<&str>,
165    password: Option<&str>,
166    signature: Option<&str>,
167    token: Option<&str>,
168    ticket: Option<&str>,
169    public_key_credential: Option<&str>,
170) -> Result<models::ClientClientWrappedSignIn, Error<AttemptSignInFactorOneError>> {
171    // add a prefix to parameters to efficiently prevent name collisions
172    let p_path_sign_in_id = sign_in_id;
173    let p_form_strategy = strategy;
174    let p_header_origin = origin;
175    let p_form_code = code;
176    let p_form_password = password;
177    let p_form_signature = signature;
178    let p_form_token = token;
179    let p_form_ticket = ticket;
180    let p_form_public_key_credential = public_key_credential;
181
182    let uri_str = format!(
183        "{}/v1/client/sign_ins/{sign_in_id}/attempt_first_factor",
184        configuration.base_path,
185        sign_in_id = crate::apis::urlencode(p_path_sign_in_id)
186    );
187    let mut req_builder = configuration
188        .client
189        .request(reqwest::Method::POST, &uri_str);
190
191    if let Some(ref apikey) = configuration.api_key {
192        let key = apikey.key.clone();
193        let value = match apikey.prefix {
194            Some(ref prefix) => format!("{prefix} {key}"),
195            None => key,
196        };
197        req_builder = req_builder.query(&[("__dev_session", value)]);
198    }
199    if let Some(ref user_agent) = configuration.user_agent {
200        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201    }
202    if let Some(param_value) = p_header_origin {
203        req_builder = req_builder.header("Origin", param_value.to_string());
204    }
205    if let Some(ref apikey) = configuration.api_key {
206        let key = apikey.key.clone();
207        let value = match apikey.prefix {
208            Some(ref prefix) => format!("{prefix} {key}"),
209            None => key,
210        };
211        req_builder = req_builder.header("__session", value);
212    };
213    let mut multipart_form_params = std::collections::HashMap::new();
214    multipart_form_params.insert("strategy", p_form_strategy.to_string());
215    if let Some(param_value) = p_form_code {
216        multipart_form_params.insert("code", param_value.to_string());
217    }
218    if let Some(param_value) = p_form_password {
219        multipart_form_params.insert("password", param_value.to_string());
220    }
221    if let Some(param_value) = p_form_signature {
222        multipart_form_params.insert("signature", param_value.to_string());
223    }
224    if let Some(param_value) = p_form_token {
225        multipart_form_params.insert("token", param_value.to_string());
226    }
227    if let Some(param_value) = p_form_ticket {
228        multipart_form_params.insert("ticket", param_value.to_string());
229    }
230    if let Some(param_value) = p_form_public_key_credential {
231        multipart_form_params.insert("public_key_credential", param_value.to_string());
232    }
233    req_builder = req_builder.form(&multipart_form_params);
234
235    let req = req_builder.build()?;
236    let resp = configuration.client.execute(req).await?;
237
238    let status = resp.status();
239    let content_type = resp
240        .headers()
241        .get("content-type")
242        .and_then(|v| v.to_str().ok())
243        .unwrap_or("application/octet-stream");
244    let content_type = super::ContentType::from(content_type);
245
246    if !status.is_client_error() && !status.is_server_error() {
247        let content = resp.text().await?;
248        match content_type {
249            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
250            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedSignIn`"))),
251            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedSignIn`")))),
252        }
253    } else {
254        let content = resp.text().await?;
255        let entity: Option<AttemptSignInFactorOneError> = serde_json::from_str(&content).ok();
256        Err(Error::ResponseError(ResponseContent {
257            status,
258            content,
259            entity,
260        }))
261    }
262}
263
264/// Attempt the second verification. Requires the sign in attempt `status` to be equal to `needs_second_factor`, and for the preparation step to have been called.
265pub async fn attempt_sign_in_factor_two(
266    configuration: &configuration::Configuration,
267    sign_in_id: &str,
268    strategy: Option<&str>,
269    code: Option<&str>,
270) -> Result<models::ClientClientWrappedSignIn, Error<AttemptSignInFactorTwoError>> {
271    // add a prefix to parameters to efficiently prevent name collisions
272    let p_path_sign_in_id = sign_in_id;
273    let p_form_strategy = strategy;
274    let p_form_code = code;
275
276    let uri_str = format!(
277        "{}/v1/client/sign_ins/{sign_in_id}/attempt_second_factor",
278        configuration.base_path,
279        sign_in_id = crate::apis::urlencode(p_path_sign_in_id)
280    );
281    let mut req_builder = configuration
282        .client
283        .request(reqwest::Method::POST, &uri_str);
284
285    if let Some(ref apikey) = configuration.api_key {
286        let key = apikey.key.clone();
287        let value = match apikey.prefix {
288            Some(ref prefix) => format!("{prefix} {key}"),
289            None => key,
290        };
291        req_builder = req_builder.query(&[("__dev_session", value)]);
292    }
293    if let Some(ref user_agent) = configuration.user_agent {
294        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
295    }
296    if let Some(ref apikey) = configuration.api_key {
297        let key = apikey.key.clone();
298        let value = match apikey.prefix {
299            Some(ref prefix) => format!("{prefix} {key}"),
300            None => key,
301        };
302        req_builder = req_builder.header("__session", value);
303    };
304    let mut multipart_form_params = std::collections::HashMap::new();
305    if let Some(param_value) = p_form_strategy {
306        multipart_form_params.insert("strategy", param_value.to_string());
307    }
308    if let Some(param_value) = p_form_code {
309        multipart_form_params.insert("code", param_value.to_string());
310    }
311    req_builder = req_builder.form(&multipart_form_params);
312
313    let req = req_builder.build()?;
314    let resp = configuration.client.execute(req).await?;
315
316    let status = resp.status();
317    let content_type = resp
318        .headers()
319        .get("content-type")
320        .and_then(|v| v.to_str().ok())
321        .unwrap_or("application/octet-stream");
322    let content_type = super::ContentType::from(content_type);
323
324    if !status.is_client_error() && !status.is_server_error() {
325        let content = resp.text().await?;
326        match content_type {
327            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
328            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedSignIn`"))),
329            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedSignIn`")))),
330        }
331    } else {
332        let content = resp.text().await?;
333        let entity: Option<AttemptSignInFactorTwoError> = serde_json::from_str(&content).ok();
334        Err(Error::ResponseError(ResponseContent {
335            status,
336            content,
337            entity,
338        }))
339    }
340}
341
342/// Creates or replaces the current Sign in object. In order to authenticate a Sign in in as few requests as possible, you can pass in parameters to this request that can identify and verify the Sign in.  Parameter rules:  If the strategy equals `phone_code`, `email_code`, `web3_[provider]_signature`, `reset_password_code` or `reset_password_phone_code` then an identifier is required.  If the strategy equals `email_link` then an identifier is required and optionally redirect_url can be supplied.  If the strategy equals `password` then both an identifier and a password is required.  If the strategy equals `oauth_[provider]` or `saml` then a redirect_url is required, and an action_complete_redirect_url is optional.  If the strategy equals `oauth_token_[provider]` then at least one of code (grant code) or token (openID token) is required. Passing only the token will probably retrieve minimal information about the user from the OAuth provider. You can pass both code and token for the best results.  If the strategy equals `ticket` then ticket is required.  If the strategy equals `passkey` then no identifier is provided.  If the strategy equals `google_one_tap` then token is required.
343pub async fn create_sign_in(
344    configuration: &configuration::Configuration,
345    origin: Option<&str>,
346    strategy: Option<&str>,
347    identifier: Option<&str>,
348    password: Option<&str>,
349    ticket: Option<&str>,
350    redirect_url: Option<&str>,
351    action_complete_redirect_url: Option<&str>,
352    transfer: Option<bool>,
353    code: Option<&str>,
354    token: Option<&str>,
355    oidc_login_hint: Option<&str>,
356    oidc_prompt: Option<&str>,
357) -> Result<models::ClientClientWrappedSignIn, Error<CreateSignInError>> {
358    // add a prefix to parameters to efficiently prevent name collisions
359    let p_header_origin = origin;
360    let p_form_strategy = strategy;
361    let p_form_identifier = identifier;
362    let p_form_password = password;
363    let p_form_ticket = ticket;
364    let p_form_redirect_url = redirect_url;
365    let p_form_action_complete_redirect_url = action_complete_redirect_url;
366    let p_form_transfer = transfer;
367    let p_form_code = code;
368    let p_form_token = token;
369    let p_form_oidc_login_hint = oidc_login_hint;
370    let p_form_oidc_prompt = oidc_prompt;
371
372    let uri_str = format!("{}/v1/client/sign_ins", configuration.base_path);
373    let mut req_builder = configuration
374        .client
375        .request(reqwest::Method::POST, &uri_str);
376
377    if let Some(ref apikey) = configuration.api_key {
378        let key = apikey.key.clone();
379        let value = match apikey.prefix {
380            Some(ref prefix) => format!("{prefix} {key}"),
381            None => key,
382        };
383        req_builder = req_builder.query(&[("__dev_session", value)]);
384    }
385    if let Some(ref user_agent) = configuration.user_agent {
386        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
387    }
388    if let Some(param_value) = p_header_origin {
389        req_builder = req_builder.header("Origin", param_value.to_string());
390    }
391    if let Some(ref apikey) = configuration.api_key {
392        let key = apikey.key.clone();
393        let value = match apikey.prefix {
394            Some(ref prefix) => format!("{prefix} {key}"),
395            None => key,
396        };
397        req_builder = req_builder.header("__session", value);
398    };
399    let mut multipart_form_params = std::collections::HashMap::new();
400    if let Some(param_value) = p_form_strategy {
401        multipart_form_params.insert("strategy", param_value.to_string());
402    }
403    if let Some(param_value) = p_form_identifier {
404        multipart_form_params.insert("identifier", param_value.to_string());
405    }
406    if let Some(param_value) = p_form_password {
407        multipart_form_params.insert("password", param_value.to_string());
408    }
409    if let Some(param_value) = p_form_ticket {
410        multipart_form_params.insert("ticket", param_value.to_string());
411    }
412    if let Some(param_value) = p_form_redirect_url {
413        multipart_form_params.insert("redirect_url", param_value.to_string());
414    }
415    if let Some(param_value) = p_form_action_complete_redirect_url {
416        multipart_form_params.insert("action_complete_redirect_url", param_value.to_string());
417    }
418    if let Some(param_value) = p_form_transfer {
419        multipart_form_params.insert("transfer", param_value.to_string());
420    }
421    if let Some(param_value) = p_form_code {
422        multipart_form_params.insert("code", param_value.to_string());
423    }
424    if let Some(param_value) = p_form_token {
425        multipart_form_params.insert("token", param_value.to_string());
426    }
427    if let Some(param_value) = p_form_oidc_login_hint {
428        multipart_form_params.insert("oidc_login_hint", param_value.to_string());
429    }
430    if let Some(param_value) = p_form_oidc_prompt {
431        multipart_form_params.insert("oidc_prompt", param_value.to_string());
432    }
433    req_builder = req_builder.form(&multipart_form_params);
434
435    let req = req_builder.build()?;
436    let resp = configuration.client.execute(req).await?;
437
438    let status = resp.status();
439    let content_type = resp
440        .headers()
441        .get("content-type")
442        .and_then(|v| v.to_str().ok())
443        .unwrap_or("application/octet-stream");
444    let content_type = super::ContentType::from(content_type);
445
446    if !status.is_client_error() && !status.is_server_error() {
447        let content = resp.text().await?;
448        match content_type {
449            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
450            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedSignIn`"))),
451            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedSignIn`")))),
452        }
453    } else {
454        let content = resp.text().await?;
455        let entity: Option<CreateSignInError> = serde_json::from_str(&content).ok();
456        Err(Error::ResponseError(ResponseContent {
457            status,
458            content,
459            entity,
460        }))
461    }
462}
463
464/// Returns the sign-in with the given id. The sign in is returned only if it belongs to the requesting client and is not abandoned.
465pub async fn get_sign_in(
466    configuration: &configuration::Configuration,
467    sign_in_id: &str,
468) -> Result<models::ClientClientWrappedSignIn, Error<GetSignInError>> {
469    // add a prefix to parameters to efficiently prevent name collisions
470    let p_path_sign_in_id = sign_in_id;
471
472    let uri_str = format!(
473        "{}/v1/client/sign_ins/{sign_in_id}",
474        configuration.base_path,
475        sign_in_id = crate::apis::urlencode(p_path_sign_in_id)
476    );
477    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
478
479    if let Some(ref apikey) = configuration.api_key {
480        let key = apikey.key.clone();
481        let value = match apikey.prefix {
482            Some(ref prefix) => format!("{prefix} {key}"),
483            None => key,
484        };
485        req_builder = req_builder.query(&[("__dev_session", value)]);
486    }
487    if let Some(ref user_agent) = configuration.user_agent {
488        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
489    }
490    if let Some(ref apikey) = configuration.api_key {
491        let key = apikey.key.clone();
492        let value = match apikey.prefix {
493            Some(ref prefix) => format!("{prefix} {key}"),
494            None => key,
495        };
496        req_builder = req_builder.header("__session", value);
497    };
498
499    let req = req_builder.build()?;
500    let resp = configuration.client.execute(req).await?;
501
502    let status = resp.status();
503    let content_type = resp
504        .headers()
505        .get("content-type")
506        .and_then(|v| v.to_str().ok())
507        .unwrap_or("application/octet-stream");
508    let content_type = super::ContentType::from(content_type);
509
510    if !status.is_client_error() && !status.is_server_error() {
511        let content = resp.text().await?;
512        match content_type {
513            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
514            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedSignIn`"))),
515            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedSignIn`")))),
516        }
517    } else {
518        let content = resp.text().await?;
519        let entity: Option<GetSignInError> = serde_json::from_str(&content).ok();
520        Err(Error::ResponseError(ResponseContent {
521            status,
522            content,
523            entity,
524        }))
525    }
526}
527
528/// Prepares the verification object for the identified Sign in. This step authenticates that the user is who they say they are. Depending on the strategy, this request will do something different.  Parameter actions: If the strategy equals email_code then this request will send an email with an OTP code. If the strategy equals phone_code then this request will send an SMS with an OTP code. If the strategy equals oauth_[provider] then this request generate a URL that the User needs to visit in order to authenticate. If the strategy equals passkey then this request will begin the passkey registration flow.  Parameter rules: If the strategy equals `oauth_[provider]` then a redirect_url is required, and an action_complete_redirect_url is optional.
529pub async fn prepare_sign_in_factor_one(
530    configuration: &configuration::Configuration,
531    sign_in_id: &str,
532    strategy: &str,
533    origin: Option<&str>,
534    email_address_id: Option<&str>,
535    phone_number_id: Option<&str>,
536    web3_wallet_id: Option<&str>,
537    passkey_id: Option<&str>,
538    redirect_url: Option<&str>,
539    action_complete_redirect_url: Option<&str>,
540    oidc_login_hint: Option<&str>,
541    oidc_prompt: Option<&str>,
542) -> Result<models::ClientClientWrappedSignIn, Error<PrepareSignInFactorOneError>> {
543    // add a prefix to parameters to efficiently prevent name collisions
544    let p_path_sign_in_id = sign_in_id;
545    let p_form_strategy = strategy;
546    let p_header_origin = origin;
547    let p_form_email_address_id = email_address_id;
548    let p_form_phone_number_id = phone_number_id;
549    let p_form_web3_wallet_id = web3_wallet_id;
550    let p_form_passkey_id = passkey_id;
551    let p_form_redirect_url = redirect_url;
552    let p_form_action_complete_redirect_url = action_complete_redirect_url;
553    let p_form_oidc_login_hint = oidc_login_hint;
554    let p_form_oidc_prompt = oidc_prompt;
555
556    let uri_str = format!(
557        "{}/v1/client/sign_ins/{sign_in_id}/prepare_first_factor",
558        configuration.base_path,
559        sign_in_id = crate::apis::urlencode(p_path_sign_in_id)
560    );
561    let mut req_builder = configuration
562        .client
563        .request(reqwest::Method::POST, &uri_str);
564
565    if let Some(ref apikey) = configuration.api_key {
566        let key = apikey.key.clone();
567        let value = match apikey.prefix {
568            Some(ref prefix) => format!("{prefix} {key}"),
569            None => key,
570        };
571        req_builder = req_builder.query(&[("__dev_session", value)]);
572    }
573    if let Some(ref user_agent) = configuration.user_agent {
574        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
575    }
576    if let Some(param_value) = p_header_origin {
577        req_builder = req_builder.header("Origin", param_value.to_string());
578    }
579    if let Some(ref apikey) = configuration.api_key {
580        let key = apikey.key.clone();
581        let value = match apikey.prefix {
582            Some(ref prefix) => format!("{prefix} {key}"),
583            None => key,
584        };
585        req_builder = req_builder.header("__session", value);
586    };
587    let mut multipart_form_params = std::collections::HashMap::new();
588    multipart_form_params.insert("strategy", p_form_strategy.to_string());
589    if let Some(param_value) = p_form_email_address_id {
590        multipart_form_params.insert("email_address_id", param_value.to_string());
591    }
592    if let Some(param_value) = p_form_phone_number_id {
593        multipart_form_params.insert("phone_number_id", param_value.to_string());
594    }
595    if let Some(param_value) = p_form_web3_wallet_id {
596        multipart_form_params.insert("web3_wallet_id", param_value.to_string());
597    }
598    if let Some(param_value) = p_form_passkey_id {
599        multipart_form_params.insert("passkey_id", param_value.to_string());
600    }
601    if let Some(param_value) = p_form_redirect_url {
602        multipart_form_params.insert("redirect_url", param_value.to_string());
603    }
604    if let Some(param_value) = p_form_action_complete_redirect_url {
605        multipart_form_params.insert("action_complete_redirect_url", param_value.to_string());
606    }
607    if let Some(param_value) = p_form_oidc_login_hint {
608        multipart_form_params.insert("oidc_login_hint", param_value.to_string());
609    }
610    if let Some(param_value) = p_form_oidc_prompt {
611        multipart_form_params.insert("oidc_prompt", param_value.to_string());
612    }
613    req_builder = req_builder.form(&multipart_form_params);
614
615    let req = req_builder.build()?;
616    let resp = configuration.client.execute(req).await?;
617
618    let status = resp.status();
619    let content_type = resp
620        .headers()
621        .get("content-type")
622        .and_then(|v| v.to_str().ok())
623        .unwrap_or("application/octet-stream");
624    let content_type = super::ContentType::from(content_type);
625
626    if !status.is_client_error() && !status.is_server_error() {
627        let content = resp.text().await?;
628        match content_type {
629            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
630            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedSignIn`"))),
631            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedSignIn`")))),
632        }
633    } else {
634        let content = resp.text().await?;
635        let entity: Option<PrepareSignInFactorOneError> = serde_json::from_str(&content).ok();
636        Err(Error::ResponseError(ResponseContent {
637            status,
638            content,
639            entity,
640        }))
641    }
642}
643
644/// Prepare the second verification. Requires the sign in attempt `status` to be equal to `needs_second_factor`.
645pub async fn prepare_sign_in_factor_two(
646    configuration: &configuration::Configuration,
647    sign_in_id: &str,
648    strategy: Option<&str>,
649    phone_number_id: Option<&str>,
650) -> Result<models::ClientClientWrappedSignIn, Error<PrepareSignInFactorTwoError>> {
651    // add a prefix to parameters to efficiently prevent name collisions
652    let p_path_sign_in_id = sign_in_id;
653    let p_form_strategy = strategy;
654    let p_form_phone_number_id = phone_number_id;
655
656    let uri_str = format!(
657        "{}/v1/client/sign_ins/{sign_in_id}/prepare_second_factor",
658        configuration.base_path,
659        sign_in_id = crate::apis::urlencode(p_path_sign_in_id)
660    );
661    let mut req_builder = configuration
662        .client
663        .request(reqwest::Method::POST, &uri_str);
664
665    if let Some(ref apikey) = configuration.api_key {
666        let key = apikey.key.clone();
667        let value = match apikey.prefix {
668            Some(ref prefix) => format!("{prefix} {key}"),
669            None => key,
670        };
671        req_builder = req_builder.query(&[("__dev_session", value)]);
672    }
673    if let Some(ref user_agent) = configuration.user_agent {
674        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
675    }
676    if let Some(ref apikey) = configuration.api_key {
677        let key = apikey.key.clone();
678        let value = match apikey.prefix {
679            Some(ref prefix) => format!("{prefix} {key}"),
680            None => key,
681        };
682        req_builder = req_builder.header("__session", value);
683    };
684    let mut multipart_form_params = std::collections::HashMap::new();
685    if let Some(param_value) = p_form_strategy {
686        multipart_form_params.insert("strategy", param_value.to_string());
687    }
688    if let Some(param_value) = p_form_phone_number_id {
689        multipart_form_params.insert("phone_number_id", param_value.to_string());
690    }
691    req_builder = req_builder.form(&multipart_form_params);
692
693    let req = req_builder.build()?;
694    let resp = configuration.client.execute(req).await?;
695
696    let status = resp.status();
697    let content_type = resp
698        .headers()
699        .get("content-type")
700        .and_then(|v| v.to_str().ok())
701        .unwrap_or("application/octet-stream");
702    let content_type = super::ContentType::from(content_type);
703
704    if !status.is_client_error() && !status.is_server_error() {
705        let content = resp.text().await?;
706        match content_type {
707            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
708            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedSignIn`"))),
709            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedSignIn`")))),
710        }
711    } else {
712        let content = resp.text().await?;
713        let entity: Option<PrepareSignInFactorTwoError> = serde_json::from_str(&content).ok();
714        Err(Error::ResponseError(ResponseContent {
715            status,
716            content,
717            entity,
718        }))
719    }
720}
721
722/// Reset password on sign-in.
723pub async fn reset_password(
724    configuration: &configuration::Configuration,
725    sign_in_id: &str,
726    password: &str,
727    sign_out_of_other_sessions: Option<bool>,
728) -> Result<models::SchemasClientClientWrappedSignIn, Error<ResetPasswordError>> {
729    // add a prefix to parameters to efficiently prevent name collisions
730    let p_path_sign_in_id = sign_in_id;
731    let p_form_password = password;
732    let p_form_sign_out_of_other_sessions = sign_out_of_other_sessions;
733
734    let uri_str = format!(
735        "{}/v1/client/sign_ins/{sign_in_id}/reset_password",
736        configuration.base_path,
737        sign_in_id = crate::apis::urlencode(p_path_sign_in_id)
738    );
739    let mut req_builder = configuration
740        .client
741        .request(reqwest::Method::POST, &uri_str);
742
743    if let Some(ref apikey) = configuration.api_key {
744        let key = apikey.key.clone();
745        let value = match apikey.prefix {
746            Some(ref prefix) => format!("{prefix} {key}"),
747            None => key,
748        };
749        req_builder = req_builder.query(&[("__dev_session", value)]);
750    }
751    if let Some(ref user_agent) = configuration.user_agent {
752        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
753    }
754    if let Some(ref apikey) = configuration.api_key {
755        let key = apikey.key.clone();
756        let value = match apikey.prefix {
757            Some(ref prefix) => format!("{prefix} {key}"),
758            None => key,
759        };
760        req_builder = req_builder.header("__session", value);
761    };
762    let mut multipart_form_params = std::collections::HashMap::new();
763    multipart_form_params.insert("password", p_form_password.to_string());
764    if let Some(param_value) = p_form_sign_out_of_other_sessions {
765        multipart_form_params.insert("sign_out_of_other_sessions", param_value.to_string());
766    }
767    req_builder = req_builder.form(&multipart_form_params);
768
769    let req = req_builder.build()?;
770    let resp = configuration.client.execute(req).await?;
771
772    let status = resp.status();
773    let content_type = resp
774        .headers()
775        .get("content-type")
776        .and_then(|v| v.to_str().ok())
777        .unwrap_or("application/octet-stream");
778    let content_type = super::ContentType::from(content_type);
779
780    if !status.is_client_error() && !status.is_server_error() {
781        let content = resp.text().await?;
782        match content_type {
783            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
784            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SchemasClientClientWrappedSignIn`"))),
785            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SchemasClientClientWrappedSignIn`")))),
786        }
787    } else {
788        let content = resp.text().await?;
789        let entity: Option<ResetPasswordError> = serde_json::from_str(&content).ok();
790        Err(Error::ResponseError(ResponseContent {
791            status,
792            content,
793            entity,
794        }))
795    }
796}
797
798/// Attempt to verify a verification with email_link strategy.
799pub async fn verify(
800    configuration: &configuration::Configuration,
801    token: &str,
802) -> Result<(), Error<VerifyError>> {
803    // add a prefix to parameters to efficiently prevent name collisions
804    let p_query_token = token;
805
806    let uri_str = format!("{}/v1/verify", configuration.base_path);
807    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
808
809    req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
810    if let Some(ref apikey) = configuration.api_key {
811        let key = apikey.key.clone();
812        let value = match apikey.prefix {
813            Some(ref prefix) => format!("{prefix} {key}"),
814            None => key,
815        };
816        req_builder = req_builder.query(&[("__dev_session", value)]);
817    }
818    if let Some(ref user_agent) = configuration.user_agent {
819        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
820    }
821    if let Some(ref apikey) = configuration.api_key {
822        let key = apikey.key.clone();
823        let value = match apikey.prefix {
824            Some(ref prefix) => format!("{prefix} {key}"),
825            None => key,
826        };
827        req_builder = req_builder.header("__session", value);
828    };
829
830    let req = req_builder.build()?;
831    let resp = configuration.client.execute(req).await?;
832
833    let status = resp.status();
834
835    if !status.is_client_error() && !status.is_server_error() {
836        Ok(())
837    } else {
838        let content = resp.text().await?;
839        let entity: Option<VerifyError> = serde_json::from_str(&content).ok();
840        Err(Error::ResponseError(ResponseContent {
841            status,
842            content,
843            entity,
844        }))
845    }
846}