sindri_openapi/apis/
token_api.rs

1/*
2 * Sindri Labs API
3 *
4 *  ## About [Sindri Labs](https://www.sindri.app/)' API simplifies the developer experience to enable fast and scalable zero-knowledge proof generation. Front-End Dashboard: [https://sindri.app/login](https://sindri.app/login) ## Documentation The [Sindri Documentation](https://sindri.app/docs) contains everything you need to get started! ## Sindri Resources The [sindri-resources GitHub repo](https://github.com/Sindri-Labs/sindri-resources) contains contains resources and sample data for the Sindri API. ## Using this Page This is a standard [OpenAPI (Swagger)](https://swagger.io/specification/) API documentation page. It provides detailed documentation for each endpoint. This page enables easy prototyping via the \"Try it out\" feature! Since all Sindri endpoints require a valid API Key, in order to use the \"Try it out\" feature for any endpoint in this documentation you must first obtain an API key. Do this in one of two ways: 1. Enter your username and password in the `/api/apikey/generate` endpoint of the **Authorization** section below. Use the API key returned in the `access` field of the response. 2. Obtain an API key from the Sindri Dashboard team \"Account Settings\". After obtaining your API key, authorize your page session by entering your API Key in the `SindriAPIKeyBearerAuth` section, reached by clicking \"Authorize\" below. Proving Backend Version: v1.2.17
5 *
6 * The version of the OpenAPI document: v1.17.28
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`jwt_token_generate`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum JwtTokenGenerateError {
20    Status403(models::JwtTokenErrorResponse),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`jwt_token_refresh`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum JwtTokenRefreshError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`jwt_token_verify`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum JwtTokenVerifyError {
35    UnknownValue(serde_json::Value),
36}
37
38/// Override the ninja_jwt default `obtain_token` method in order to add email verification check before generating a token.
39pub async fn jwt_token_generate(
40    configuration: &configuration::Configuration,
41    token_obtain_pair_input_schema: models::TokenObtainPairInputSchema,
42) -> Result<models::TokenObtainPairOutputSchema, Error<JwtTokenGenerateError>> {
43    // add a prefix to parameters to efficiently prevent name collisions
44    let p_token_obtain_pair_input_schema = token_obtain_pair_input_schema;
45
46    let uri_str = format!("{}/api/token/pair", configuration.base_path);
47    let mut req_builder = configuration
48        .client
49        .request(reqwest::Method::POST, &uri_str);
50
51    if let Some(ref user_agent) = configuration.user_agent {
52        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53    }
54    req_builder = req_builder.json(&p_token_obtain_pair_input_schema);
55
56    let req = req_builder.build()?;
57    let resp = configuration.client.execute(req).await?;
58
59    let status = resp.status();
60
61    if !status.is_client_error() && !status.is_server_error() {
62        let content = resp.text().await?;
63        serde_json::from_str(&content).map_err(Error::from)
64    } else {
65        let content = resp.text().await?;
66        let entity: Option<JwtTokenGenerateError> = serde_json::from_str(&content).ok();
67        Err(Error::ResponseError(ResponseContent {
68            status,
69            content,
70            entity,
71        }))
72    }
73}
74
75pub async fn jwt_token_refresh(
76    configuration: &configuration::Configuration,
77    token_refresh_input_schema: models::TokenRefreshInputSchema,
78) -> Result<models::TokenRefreshOutputSchema, Error<JwtTokenRefreshError>> {
79    // add a prefix to parameters to efficiently prevent name collisions
80    let p_token_refresh_input_schema = token_refresh_input_schema;
81
82    let uri_str = format!("{}/api/token/refresh", configuration.base_path);
83    let mut req_builder = configuration
84        .client
85        .request(reqwest::Method::POST, &uri_str);
86
87    if let Some(ref user_agent) = configuration.user_agent {
88        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89    }
90    req_builder = req_builder.json(&p_token_refresh_input_schema);
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96
97    if !status.is_client_error() && !status.is_server_error() {
98        let content = resp.text().await?;
99        serde_json::from_str(&content).map_err(Error::from)
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<JwtTokenRefreshError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent {
104            status,
105            content,
106            entity,
107        }))
108    }
109}
110
111pub async fn jwt_token_verify(
112    configuration: &configuration::Configuration,
113    token_verify_input_schema: models::TokenVerifyInputSchema,
114) -> Result<serde_json::Value, Error<JwtTokenVerifyError>> {
115    // add a prefix to parameters to efficiently prevent name collisions
116    let p_token_verify_input_schema = token_verify_input_schema;
117
118    let uri_str = format!("{}/api/token/verify", configuration.base_path);
119    let mut req_builder = configuration
120        .client
121        .request(reqwest::Method::POST, &uri_str);
122
123    if let Some(ref user_agent) = configuration.user_agent {
124        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
125    }
126    req_builder = req_builder.json(&p_token_verify_input_schema);
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        serde_json::from_str(&content).map_err(Error::from)
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<JwtTokenVerifyError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent {
140            status,
141            content,
142            entity,
143        }))
144    }
145}