open_api_hydra/apis/
public_api.rs

1/*
2 * ORY Hydra
3 *
4 * Welcome to the ORY Hydra HTTP API documentation. You will find documentation for all HTTP APIs here.
5 *
6 * The version of the OpenAPI document: latest
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `disconnect_user`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DisconnectUserError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method `discover_open_id_configuration`
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DiscoverOpenIdConfigurationError {
29    Status401(crate::models::GenericError),
30    Status500(crate::models::GenericError),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `is_instance_ready`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum IsInstanceReadyError {
38    Status503(crate::models::HealthNotReadyStatus),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `oauth2_token`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum Oauth2TokenError {
46    Status401(crate::models::GenericError),
47    Status500(crate::models::GenericError),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method `oauth_auth`
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum OauthAuthError {
55    Status401(crate::models::GenericError),
56    Status500(crate::models::GenericError),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method `revoke_o_auth2_token`
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum RevokeOAuth2TokenError {
64    Status401(crate::models::GenericError),
65    Status500(crate::models::GenericError),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method `userinfo`
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum UserinfoError {
73    Status401(crate::models::GenericError),
74    Status500(crate::models::GenericError),
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method `well_known`
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum WellKnownError {
82    Status500(crate::models::GenericError),
83    UnknownValue(serde_json::Value),
84}
85
86
87/// This endpoint initiates and completes user logout at ORY Hydra and initiates OpenID Connect Front-/Back-channel logout:  https://openid.net/specs/openid-connect-frontchannel-1_0.html https://openid.net/specs/openid-connect-backchannel-1_0.html
88pub async fn disconnect_user(configuration: &configuration::Configuration, ) -> Result<(), Error<DisconnectUserError>> {
89
90    let local_var_client = &configuration.client;
91
92    let local_var_uri_str = format!("{}/oauth2/sessions/logout", configuration.base_path);
93    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
94
95    if let Some(ref local_var_user_agent) = configuration.user_agent {
96        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97    }
98
99    let local_var_req = local_var_req_builder.build()?;
100    let local_var_resp = local_var_client.execute(local_var_req).await?;
101
102    let local_var_status = local_var_resp.status();
103    let local_var_content = local_var_resp.text().await?;
104
105    if local_var_status.is_success() {
106        Ok(())
107    } else {
108        let local_var_entity: Option<DisconnectUserError> = serde_json::from_str(&local_var_content).ok();
109        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
110        Err(Error::ResponseError(local_var_error))
111    }
112}
113
114/// The well known endpoint an be used to retrieve information for OpenID Connect clients. We encourage you to not roll your own OpenID Connect client but to use an OpenID Connect client library instead. You can learn more on this flow at https://openid.net/specs/openid-connect-discovery-1_0.html .  Popular libraries for OpenID Connect clients include oidc-client-js (JavaScript), go-oidc (Golang), and others. For a full list of clients go here: https://openid.net/developers/certified/
115pub async fn discover_open_id_configuration(configuration: &configuration::Configuration, ) -> Result<crate::models::WellKnown, Error<DiscoverOpenIdConfigurationError>> {
116
117    let local_var_client = &configuration.client;
118
119    let local_var_uri_str = format!("{}/.well-known/openid-configuration", configuration.base_path);
120    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
121
122    if let Some(ref local_var_user_agent) = configuration.user_agent {
123        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
124    }
125
126    let local_var_req = local_var_req_builder.build()?;
127    let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129    let local_var_status = local_var_resp.status();
130    let local_var_content = local_var_resp.text().await?;
131
132    if local_var_status.is_success() {
133        serde_json::from_str(&local_var_content).map_err(Error::from)
134    } else {
135        let local_var_entity: Option<DiscoverOpenIdConfigurationError> = serde_json::from_str(&local_var_content).ok();
136        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
137        Err(Error::ResponseError(local_var_error))
138    }
139}
140
141/// This endpoint returns a 200 status code when the HTTP server is up running and the environment dependencies (e.g. the database) are responsive as well.  If the service supports TLS Edge Termination, this endpoint does not require the `X-Forwarded-Proto` header to be set.  Be aware that if you are running multiple nodes of this service, the health status will never refer to the cluster state, only to a single instance.
142pub async fn is_instance_ready(configuration: &configuration::Configuration, ) -> Result<crate::models::HealthStatus, Error<IsInstanceReadyError>> {
143
144    let local_var_client = &configuration.client;
145
146    let local_var_uri_str = format!("{}/health/ready", configuration.base_path);
147    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
148
149    if let Some(ref local_var_user_agent) = configuration.user_agent {
150        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
151    }
152
153    let local_var_req = local_var_req_builder.build()?;
154    let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156    let local_var_status = local_var_resp.status();
157    let local_var_content = local_var_resp.text().await?;
158
159    if local_var_status.is_success() {
160        serde_json::from_str(&local_var_content).map_err(Error::from)
161    } else {
162        let local_var_entity: Option<IsInstanceReadyError> = serde_json::from_str(&local_var_content).ok();
163        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
164        Err(Error::ResponseError(local_var_error))
165    }
166}
167
168/// The client makes a request to the token endpoint by sending the following parameters using the \"application/x-www-form-urlencoded\" HTTP request entity-body.  > Do not implement a client for this endpoint yourself. Use a library. There are many libraries > available for any programming language. You can find a list of libraries here: https://oauth.net/code/ > > Do not the the Hydra SDK does not implement this endpoint properly. Use one of the libraries listed above!
169pub async fn oauth2_token(configuration: &configuration::Configuration, grant_type: &str, code: Option<&str>, refresh_token: Option<&str>, redirect_uri: Option<&str>, client_id: Option<&str>) -> Result<crate::models::Oauth2TokenResponse, Error<Oauth2TokenError>> {
170
171    let local_var_client = &configuration.client;
172
173    let local_var_uri_str = format!("{}/oauth2/token", configuration.base_path);
174    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
175
176    if let Some(ref local_var_user_agent) = configuration.user_agent {
177        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
178    }
179    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
180        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
181    };
182    if let Some(ref local_var_token) = configuration.oauth_access_token {
183        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184    };
185    let mut local_var_form_params = std::collections::HashMap::new();
186    local_var_form_params.insert("grant_type", grant_type.to_string());
187    if let Some(local_var_param_value) = code {
188        local_var_form_params.insert("code", local_var_param_value.to_string());
189    }
190    if let Some(local_var_param_value) = refresh_token {
191        local_var_form_params.insert("refresh_token", local_var_param_value.to_string());
192    }
193    if let Some(local_var_param_value) = redirect_uri {
194        local_var_form_params.insert("redirect_uri", local_var_param_value.to_string());
195    }
196    if let Some(local_var_param_value) = client_id {
197        local_var_form_params.insert("client_id", local_var_param_value.to_string());
198    }
199    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
200
201    let local_var_req = local_var_req_builder.build()?;
202    let local_var_resp = local_var_client.execute(local_var_req).await?;
203
204    let local_var_status = local_var_resp.status();
205    let local_var_content = local_var_resp.text().await?;
206
207    if local_var_status.is_success() {
208        serde_json::from_str(&local_var_content).map_err(Error::from)
209    } else {
210        let local_var_entity: Option<Oauth2TokenError> = serde_json::from_str(&local_var_content).ok();
211        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
212        Err(Error::ResponseError(local_var_error))
213    }
214}
215
216/// This endpoint is not documented here because you should never use your own implementation to perform OAuth2 flows. OAuth2 is a very popular protocol and a library for your programming language will exists.  To learn more about this flow please refer to the specification: https://tools.ietf.org/html/rfc6749
217pub async fn oauth_auth(configuration: &configuration::Configuration, ) -> Result<(), Error<OauthAuthError>> {
218
219    let local_var_client = &configuration.client;
220
221    let local_var_uri_str = format!("{}/oauth2/auth", configuration.base_path);
222    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
223
224    if let Some(ref local_var_user_agent) = configuration.user_agent {
225        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226    }
227
228    let local_var_req = local_var_req_builder.build()?;
229    let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231    let local_var_status = local_var_resp.status();
232    let local_var_content = local_var_resp.text().await?;
233
234    if local_var_status.is_success() {
235        Ok(())
236    } else {
237        let local_var_entity: Option<OauthAuthError> = serde_json::from_str(&local_var_content).ok();
238        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239        Err(Error::ResponseError(local_var_error))
240    }
241}
242
243/// Revoking a token (both access and refresh) means that the tokens will be invalid. A revoked access token can no longer be used to make access requests, and a revoked refresh token can no longer be used to refresh an access token. Revoking a refresh token also invalidates the access token that was created with it. A token may only be revoked by the client the token was generated for.
244pub async fn revoke_o_auth2_token(configuration: &configuration::Configuration, token: &str) -> Result<(), Error<RevokeOAuth2TokenError>> {
245
246    let local_var_client = &configuration.client;
247
248    let local_var_uri_str = format!("{}/oauth2/revoke", configuration.base_path);
249    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
250
251    if let Some(ref local_var_user_agent) = configuration.user_agent {
252        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
253    }
254    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
255        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
256    };
257    if let Some(ref local_var_token) = configuration.oauth_access_token {
258        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
259    };
260    let mut local_var_form_params = std::collections::HashMap::new();
261    local_var_form_params.insert("token", token.to_string());
262    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
263
264    let local_var_req = local_var_req_builder.build()?;
265    let local_var_resp = local_var_client.execute(local_var_req).await?;
266
267    let local_var_status = local_var_resp.status();
268    let local_var_content = local_var_resp.text().await?;
269
270    if local_var_status.is_success() {
271        Ok(())
272    } else {
273        let local_var_entity: Option<RevokeOAuth2TokenError> = serde_json::from_str(&local_var_content).ok();
274        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
275        Err(Error::ResponseError(local_var_error))
276    }
277}
278
279/// This endpoint returns the payload of the ID Token, including the idTokenExtra values, of the provided OAuth 2.0 Access Token.  For more information please [refer to the spec](http://openid.net/specs/openid-connect-core-1_0.html#UserInfo).
280pub async fn userinfo(configuration: &configuration::Configuration, ) -> Result<crate::models::UserinfoResponse, Error<UserinfoError>> {
281
282    let local_var_client = &configuration.client;
283
284    let local_var_uri_str = format!("{}/userinfo", configuration.base_path);
285    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
286
287    if let Some(ref local_var_user_agent) = configuration.user_agent {
288        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289    }
290    if let Some(ref local_var_token) = configuration.oauth_access_token {
291        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
292    };
293
294    let local_var_req = local_var_req_builder.build()?;
295    let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297    let local_var_status = local_var_resp.status();
298    let local_var_content = local_var_resp.text().await?;
299
300    if local_var_status.is_success() {
301        serde_json::from_str(&local_var_content).map_err(Error::from)
302    } else {
303        let local_var_entity: Option<UserinfoError> = serde_json::from_str(&local_var_content).ok();
304        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
305        Err(Error::ResponseError(local_var_error))
306    }
307}
308
309/// This endpoint returns JSON Web Keys to be used as public keys for verifying OpenID Connect ID Tokens and, if enabled, OAuth 2.0 JWT Access Tokens. This endpoint can be used with client libraries like [node-jwks-rsa](https://github.com/auth0/node-jwks-rsa) among others.
310pub async fn well_known(configuration: &configuration::Configuration, ) -> Result<crate::models::JsonWebKeySet, Error<WellKnownError>> {
311
312    let local_var_client = &configuration.client;
313
314    let local_var_uri_str = format!("{}/.well-known/jwks.json", configuration.base_path);
315    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
316
317    if let Some(ref local_var_user_agent) = configuration.user_agent {
318        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
319    }
320
321    let local_var_req = local_var_req_builder.build()?;
322    let local_var_resp = local_var_client.execute(local_var_req).await?;
323
324    let local_var_status = local_var_resp.status();
325    let local_var_content = local_var_resp.text().await?;
326
327    if local_var_status.is_success() {
328        serde_json::from_str(&local_var_content).map_err(Error::from)
329    } else {
330        let local_var_entity: Option<WellKnownError> = serde_json::from_str(&local_var_content).ok();
331        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
332        Err(Error::ResponseError(local_var_error))
333    }
334}
335