memos_api/apis/
auth_service_api.rs

1/*
2 * Memos API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
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 [`auth_service_get_auth_status`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AuthServiceGetAuthStatusError {
22    DefaultResponse(models::GooglerpcStatus),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`auth_service_sign_in`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum AuthServiceSignInError {
30    DefaultResponse(models::GooglerpcStatus),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`auth_service_sign_in_with_sso`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum AuthServiceSignInWithSsoError {
38    DefaultResponse(models::GooglerpcStatus),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`auth_service_sign_out`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum AuthServiceSignOutError {
46    DefaultResponse(models::GooglerpcStatus),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`auth_service_sign_up`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum AuthServiceSignUpError {
54    DefaultResponse(models::GooglerpcStatus),
55    UnknownValue(serde_json::Value),
56}
57
58
59pub fn auth_service_get_auth_status(configuration: &configuration::Configuration, ) -> Result<models::V1User, Error<AuthServiceGetAuthStatusError>> {
60    let local_var_configuration = configuration;
61
62    let local_var_client = &local_var_configuration.client;
63
64    let local_var_uri_str = format!("{}/api/v1/auth/status", local_var_configuration.base_path);
65    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
66
67    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
68        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
69    }
70    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
71        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
72    };
73
74    let local_var_req = local_var_req_builder.build()?;
75    let local_var_resp = local_var_client.execute(local_var_req)?;
76
77    let local_var_status = local_var_resp.status();
78    let local_var_content = local_var_resp.text()?;
79
80    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81        serde_json::from_str(&local_var_content).map_err(Error::from)
82    } else {
83        let local_var_entity: Option<AuthServiceGetAuthStatusError> = serde_json::from_str(&local_var_content).ok();
84        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
85        Err(Error::ResponseError(local_var_error))
86    }
87}
88
89pub fn auth_service_sign_in(configuration: &configuration::Configuration, username: Option<&str>, password: Option<&str>, never_expire: Option<bool>) -> Result<models::V1User, Error<AuthServiceSignInError>> {
90    let local_var_configuration = configuration;
91
92    let local_var_client = &local_var_configuration.client;
93
94    let local_var_uri_str = format!("{}/api/v1/auth/signin", local_var_configuration.base_path);
95    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
96
97    if let Some(ref local_var_str) = username {
98        local_var_req_builder = local_var_req_builder.query(&[("username", &local_var_str.to_string())]);
99    }
100    if let Some(ref local_var_str) = password {
101        local_var_req_builder = local_var_req_builder.query(&[("password", &local_var_str.to_string())]);
102    }
103    if let Some(ref local_var_str) = never_expire {
104        local_var_req_builder = local_var_req_builder.query(&[("neverExpire", &local_var_str.to_string())]);
105    }
106    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
107        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
108    }
109
110    let local_var_req = local_var_req_builder.build()?;
111    let local_var_resp = local_var_client.execute(local_var_req)?;
112
113    let local_var_status = local_var_resp.status();
114    let local_var_content = local_var_resp.text()?;
115
116    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117        serde_json::from_str(&local_var_content).map_err(Error::from)
118    } else {
119        let local_var_entity: Option<AuthServiceSignInError> = serde_json::from_str(&local_var_content).ok();
120        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
121        Err(Error::ResponseError(local_var_error))
122    }
123}
124
125pub fn auth_service_sign_in_with_sso(configuration: &configuration::Configuration, idp_id: Option<i32>, code: Option<&str>, redirect_uri: Option<&str>) -> Result<models::V1User, Error<AuthServiceSignInWithSsoError>> {
126    let local_var_configuration = configuration;
127
128    let local_var_client = &local_var_configuration.client;
129
130    let local_var_uri_str = format!("{}/api/v1/auth/signin/sso", local_var_configuration.base_path);
131    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133    if let Some(ref local_var_str) = idp_id {
134        local_var_req_builder = local_var_req_builder.query(&[("idpId", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_str) = code {
137        local_var_req_builder = local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
138    }
139    if let Some(ref local_var_str) = redirect_uri {
140        local_var_req_builder = local_var_req_builder.query(&[("redirectUri", &local_var_str.to_string())]);
141    }
142    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
143        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
144    }
145
146    let local_var_req = local_var_req_builder.build()?;
147    let local_var_resp = local_var_client.execute(local_var_req)?;
148
149    let local_var_status = local_var_resp.status();
150    let local_var_content = local_var_resp.text()?;
151
152    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153        serde_json::from_str(&local_var_content).map_err(Error::from)
154    } else {
155        let local_var_entity: Option<AuthServiceSignInWithSsoError> = serde_json::from_str(&local_var_content).ok();
156        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
157        Err(Error::ResponseError(local_var_error))
158    }
159}
160
161pub fn auth_service_sign_out(configuration: &configuration::Configuration, ) -> Result<serde_json::Value, Error<AuthServiceSignOutError>> {
162    let local_var_configuration = configuration;
163
164    let local_var_client = &local_var_configuration.client;
165
166    let local_var_uri_str = format!("{}/api/v1/auth/signout", local_var_configuration.base_path);
167    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
168
169    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
170        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
171    }
172
173    let local_var_req = local_var_req_builder.build()?;
174    let local_var_resp = local_var_client.execute(local_var_req)?;
175
176    let local_var_status = local_var_resp.status();
177    let local_var_content = local_var_resp.text()?;
178
179    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
180        serde_json::from_str(&local_var_content).map_err(Error::from)
181    } else {
182        let local_var_entity: Option<AuthServiceSignOutError> = serde_json::from_str(&local_var_content).ok();
183        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
184        Err(Error::ResponseError(local_var_error))
185    }
186}
187
188pub fn auth_service_sign_up(configuration: &configuration::Configuration, username: Option<&str>, password: Option<&str>) -> Result<models::V1User, Error<AuthServiceSignUpError>> {
189    let local_var_configuration = configuration;
190
191    let local_var_client = &local_var_configuration.client;
192
193    let local_var_uri_str = format!("{}/api/v1/auth/signup", local_var_configuration.base_path);
194    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
195
196    if let Some(ref local_var_str) = username {
197        local_var_req_builder = local_var_req_builder.query(&[("username", &local_var_str.to_string())]);
198    }
199    if let Some(ref local_var_str) = password {
200        local_var_req_builder = local_var_req_builder.query(&[("password", &local_var_str.to_string())]);
201    }
202    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
203        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
204    }
205
206    let local_var_req = local_var_req_builder.build()?;
207    let local_var_resp = local_var_client.execute(local_var_req)?;
208
209    let local_var_status = local_var_resp.status();
210    let local_var_content = local_var_resp.text()?;
211
212    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213        serde_json::from_str(&local_var_content).map_err(Error::from)
214    } else {
215        let local_var_entity: Option<AuthServiceSignUpError> = serde_json::from_str(&local_var_content).ok();
216        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
217        Err(Error::ResponseError(local_var_error))
218    }
219}
220