clerk_fapi_rs/apis/dev_browser_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 [`create_dev_browser`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateDevBrowserError {
20 Status400(),
21 UnknownValue(serde_json::Value),
22}
23
24/* Example dev_browser response
25{
26 "id":"dvb_2wBEszr0o5v3XbETMqF0Ykerrf3",
27 "instance_id":"ins_2gXOIJSz5hpsl5tA0NMptraBFJk",
28 "token":"ey...",
29 "client_id":null,
30 "created_at":"2025-04-24T14:59:37.240941608Z",
31 "updated_at":"2025-04-24T14:59:37.240941608Z",
32 "home_origin":null
33}
34*/
35#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
36pub struct DevBrowser {
37 pub id: String,
38 pub instance_id: String,
39 pub token: String,
40 pub client_id: Option<String>,
41 pub created_at: String,
42 pub updated_at: String,
43 pub home_origin: Option<String>,
44}
45
46/// Generate an Dev Browser API token. This is used to authenticate Development Instances with the `DevBrowser` scheme. It must be set before making any request to a dev instance, even for endpoints that are public.
47pub async fn create_dev_browser(
48 configuration: &configuration::Configuration,
49) -> Result<DevBrowser, Error<CreateDevBrowserError>> {
50 let uri_str = format!("{}/v1/dev_browser", configuration.base_path);
51 let mut req_builder = configuration
52 .client
53 .request(reqwest::Method::POST, &uri_str);
54
55 if let Some(ref user_agent) = configuration.user_agent {
56 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
57 }
58
59 let req = req_builder.build()?;
60 let resp = configuration.client.execute(req).await?;
61
62 let status = resp.status();
63 let content = resp.text().await?;
64
65 if !status.is_client_error() && !status.is_server_error() {
66 serde_json::from_str(&content).map_err(Error::from)
67 } else {
68 let entity: Option<CreateDevBrowserError> = serde_json::from_str(&content).ok();
69 Err(Error::ResponseError(ResponseContent {
70 status,
71 content,
72 entity,
73 }))
74 }
75}