ory_client/apis/
jwk_api.rs

1/*
2 * Ory APIs
3 *
4 * # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers.  ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages:  | Language       | Download SDK                                                     | Documentation                                                                        | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart           | [pub.dev](https://pub.dev/packages/ory_client)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md)       | | .NET           | [nuget.org](https://www.nuget.org/packages/Ory.Client/)          | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md)     | | Elixir         | [hex.pm](https://hex.pm/packages/ory_client)                     | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md)     | | Go             | [github.com](https://github.com/ory/client-go)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md)         | | Java           | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md)       | | JavaScript     | [npmjs.com](https://www.npmjs.com/package/@ory/client)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) |  | PHP            | [packagist.org](https://packagist.org/packages/ory/client)       | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md)        | | Python         | [pypi.org](https://pypi.org/project/ory-client/)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md)     | | Ruby           | [rubygems.org](https://rubygems.org/gems/ory-client)             | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md)       | | Rust           | [crates.io](https://crates.io/crates/ory-client)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md)       | 
5 *
6 * The version of the OpenAPI document: v1.22.4
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`create_json_web_key_set`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateJsonWebKeySetError {
22    DefaultResponse(models::ErrorOAuth2),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_json_web_key`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteJsonWebKeyError {
30    DefaultResponse(models::ErrorOAuth2),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`delete_json_web_key_set`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DeleteJsonWebKeySetError {
38    DefaultResponse(models::ErrorOAuth2),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_json_web_key`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetJsonWebKeyError {
46    DefaultResponse(models::ErrorOAuth2),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_json_web_key_set`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetJsonWebKeySetError {
54    DefaultResponse(models::ErrorOAuth2),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`set_json_web_key`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum SetJsonWebKeyError {
62    DefaultResponse(models::ErrorOAuth2),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`set_json_web_key_set`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum SetJsonWebKeySetError {
70    DefaultResponse(models::ErrorOAuth2),
71    UnknownValue(serde_json::Value),
72}
73
74
75/// This endpoint is capable of generating JSON Web Key Sets for you. There a different strategies available, such as symmetric cryptographic keys (HS256, HS512) and asymetric cryptographic keys (RS256, ECDSA). If the specified JSON Web Key Set does not exist, it will be created.  A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. A JWK Set is a JSON data structure that represents a set of JWKs. A JSON Web Key is identified by its set and key id. ORY Hydra uses this functionality to store cryptographic keys used for TLS and JSON Web Tokens (such as OpenID Connect ID tokens), and allows storing user-defined keys as well.
76pub async fn create_json_web_key_set(configuration: &configuration::Configuration, set: &str, create_json_web_key_set: models::CreateJsonWebKeySet) -> Result<models::JsonWebKeySet, Error<CreateJsonWebKeySetError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_set = set;
79    let p_create_json_web_key_set = create_json_web_key_set;
80
81    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
82    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref token) = configuration.bearer_access_token {
88        req_builder = req_builder.bearer_auth(token.to_owned());
89    };
90    req_builder = req_builder.json(&p_create_json_web_key_set);
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96    let content_type = resp
97        .headers()
98        .get("content-type")
99        .and_then(|v| v.to_str().ok())
100        .unwrap_or("application/octet-stream");
101    let content_type = super::ContentType::from(content_type);
102
103    if !status.is_client_error() && !status.is_server_error() {
104        let content = resp.text().await?;
105        match content_type {
106            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
108            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::JsonWebKeySet`")))),
109        }
110    } else {
111        let content = resp.text().await?;
112        let entity: Option<CreateJsonWebKeySetError> = serde_json::from_str(&content).ok();
113        Err(Error::ResponseError(ResponseContent { status, content, entity }))
114    }
115}
116
117/// Use this endpoint to delete a single JSON Web Key.  A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. A JWK Set is a JSON data structure that represents a set of JWKs. A JSON Web Key is identified by its set and key id. ORY Hydra uses this functionality to store cryptographic keys used for TLS and JSON Web Tokens (such as OpenID Connect ID tokens), and allows storing user-defined keys as well.
118pub async fn delete_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str) -> Result<(), Error<DeleteJsonWebKeyError>> {
119    // add a prefix to parameters to efficiently prevent name collisions
120    let p_set = set;
121    let p_kid = kid;
122
123    let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_set), kid=crate::apis::urlencode(p_kid));
124    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
125
126    if let Some(ref user_agent) = configuration.user_agent {
127        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128    }
129    if let Some(ref token) = configuration.bearer_access_token {
130        req_builder = req_builder.bearer_auth(token.to_owned());
131    };
132
133    let req = req_builder.build()?;
134    let resp = configuration.client.execute(req).await?;
135
136    let status = resp.status();
137
138    if !status.is_client_error() && !status.is_server_error() {
139        Ok(())
140    } else {
141        let content = resp.text().await?;
142        let entity: Option<DeleteJsonWebKeyError> = serde_json::from_str(&content).ok();
143        Err(Error::ResponseError(ResponseContent { status, content, entity }))
144    }
145}
146
147/// Use this endpoint to delete a complete JSON Web Key Set and all the keys in that set.  A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. A JWK Set is a JSON data structure that represents a set of JWKs. A JSON Web Key is identified by its set and key id. ORY Hydra uses this functionality to store cryptographic keys used for TLS and JSON Web Tokens (such as OpenID Connect ID tokens), and allows storing user-defined keys as well.
148pub async fn delete_json_web_key_set(configuration: &configuration::Configuration, set: &str) -> Result<(), Error<DeleteJsonWebKeySetError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_set = set;
151
152    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
153    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
154
155    if let Some(ref user_agent) = configuration.user_agent {
156        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157    }
158    if let Some(ref token) = configuration.bearer_access_token {
159        req_builder = req_builder.bearer_auth(token.to_owned());
160    };
161
162    let req = req_builder.build()?;
163    let resp = configuration.client.execute(req).await?;
164
165    let status = resp.status();
166
167    if !status.is_client_error() && !status.is_server_error() {
168        Ok(())
169    } else {
170        let content = resp.text().await?;
171        let entity: Option<DeleteJsonWebKeySetError> = serde_json::from_str(&content).ok();
172        Err(Error::ResponseError(ResponseContent { status, content, entity }))
173    }
174}
175
176/// This endpoint returns a singular JSON Web Key contained in a set. It is identified by the set and the specific key ID (kid).
177pub async fn get_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str) -> Result<models::JsonWebKeySet, Error<GetJsonWebKeyError>> {
178    // add a prefix to parameters to efficiently prevent name collisions
179    let p_set = set;
180    let p_kid = kid;
181
182    let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_set), kid=crate::apis::urlencode(p_kid));
183    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185    if let Some(ref user_agent) = configuration.user_agent {
186        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187    }
188    if let Some(ref token) = configuration.bearer_access_token {
189        req_builder = req_builder.bearer_auth(token.to_owned());
190    };
191
192    let req = req_builder.build()?;
193    let resp = configuration.client.execute(req).await?;
194
195    let status = resp.status();
196    let content_type = resp
197        .headers()
198        .get("content-type")
199        .and_then(|v| v.to_str().ok())
200        .unwrap_or("application/octet-stream");
201    let content_type = super::ContentType::from(content_type);
202
203    if !status.is_client_error() && !status.is_server_error() {
204        let content = resp.text().await?;
205        match content_type {
206            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
207            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
208            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::JsonWebKeySet`")))),
209        }
210    } else {
211        let content = resp.text().await?;
212        let entity: Option<GetJsonWebKeyError> = serde_json::from_str(&content).ok();
213        Err(Error::ResponseError(ResponseContent { status, content, entity }))
214    }
215}
216
217/// This endpoint can be used to retrieve JWK Sets stored in ORY Hydra.  A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. A JWK Set is a JSON data structure that represents a set of JWKs. A JSON Web Key is identified by its set and key id. ORY Hydra uses this functionality to store cryptographic keys used for TLS and JSON Web Tokens (such as OpenID Connect ID tokens), and allows storing user-defined keys as well.
218pub async fn get_json_web_key_set(configuration: &configuration::Configuration, set: &str) -> Result<models::JsonWebKeySet, Error<GetJsonWebKeySetError>> {
219    // add a prefix to parameters to efficiently prevent name collisions
220    let p_set = set;
221
222    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
223    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
224
225    if let Some(ref user_agent) = configuration.user_agent {
226        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
227    }
228    if let Some(ref token) = configuration.bearer_access_token {
229        req_builder = req_builder.bearer_auth(token.to_owned());
230    };
231
232    let req = req_builder.build()?;
233    let resp = configuration.client.execute(req).await?;
234
235    let status = resp.status();
236    let content_type = resp
237        .headers()
238        .get("content-type")
239        .and_then(|v| v.to_str().ok())
240        .unwrap_or("application/octet-stream");
241    let content_type = super::ContentType::from(content_type);
242
243    if !status.is_client_error() && !status.is_server_error() {
244        let content = resp.text().await?;
245        match content_type {
246            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
247            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
248            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::JsonWebKeySet`")))),
249        }
250    } else {
251        let content = resp.text().await?;
252        let entity: Option<GetJsonWebKeySetError> = serde_json::from_str(&content).ok();
253        Err(Error::ResponseError(ResponseContent { status, content, entity }))
254    }
255}
256
257/// Use this method if you do not want to let Hydra generate the JWKs for you, but instead save your own.  A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. A JWK Set is a JSON data structure that represents a set of JWKs. A JSON Web Key is identified by its set and key id. ORY Hydra uses this functionality to store cryptographic keys used for TLS and JSON Web Tokens (such as OpenID Connect ID tokens), and allows storing user-defined keys as well.
258pub async fn set_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str, json_web_key: Option<models::JsonWebKey>) -> Result<models::JsonWebKey, Error<SetJsonWebKeyError>> {
259    // add a prefix to parameters to efficiently prevent name collisions
260    let p_set = set;
261    let p_kid = kid;
262    let p_json_web_key = json_web_key;
263
264    let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_set), kid=crate::apis::urlencode(p_kid));
265    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
266
267    if let Some(ref user_agent) = configuration.user_agent {
268        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
269    }
270    if let Some(ref token) = configuration.bearer_access_token {
271        req_builder = req_builder.bearer_auth(token.to_owned());
272    };
273    req_builder = req_builder.json(&p_json_web_key);
274
275    let req = req_builder.build()?;
276    let resp = configuration.client.execute(req).await?;
277
278    let status = resp.status();
279    let content_type = resp
280        .headers()
281        .get("content-type")
282        .and_then(|v| v.to_str().ok())
283        .unwrap_or("application/octet-stream");
284    let content_type = super::ContentType::from(content_type);
285
286    if !status.is_client_error() && !status.is_server_error() {
287        let content = resp.text().await?;
288        match content_type {
289            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
290            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKey`"))),
291            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::JsonWebKey`")))),
292        }
293    } else {
294        let content = resp.text().await?;
295        let entity: Option<SetJsonWebKeyError> = serde_json::from_str(&content).ok();
296        Err(Error::ResponseError(ResponseContent { status, content, entity }))
297    }
298}
299
300/// Use this method if you do not want to let Hydra generate the JWKs for you, but instead save your own.  A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. A JWK Set is a JSON data structure that represents a set of JWKs. A JSON Web Key is identified by its set and key id. ORY Hydra uses this functionality to store cryptographic keys used for TLS and JSON Web Tokens (such as OpenID Connect ID tokens), and allows storing user-defined keys as well.
301pub async fn set_json_web_key_set(configuration: &configuration::Configuration, set: &str, json_web_key_set: Option<models::JsonWebKeySet>) -> Result<models::JsonWebKeySet, Error<SetJsonWebKeySetError>> {
302    // add a prefix to parameters to efficiently prevent name collisions
303    let p_set = set;
304    let p_json_web_key_set = json_web_key_set;
305
306    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
307    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
308
309    if let Some(ref user_agent) = configuration.user_agent {
310        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
311    }
312    if let Some(ref token) = configuration.bearer_access_token {
313        req_builder = req_builder.bearer_auth(token.to_owned());
314    };
315    req_builder = req_builder.json(&p_json_web_key_set);
316
317    let req = req_builder.build()?;
318    let resp = configuration.client.execute(req).await?;
319
320    let status = resp.status();
321    let content_type = resp
322        .headers()
323        .get("content-type")
324        .and_then(|v| v.to_str().ok())
325        .unwrap_or("application/octet-stream");
326    let content_type = super::ContentType::from(content_type);
327
328    if !status.is_client_error() && !status.is_server_error() {
329        let content = resp.text().await?;
330        match content_type {
331            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
332            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
333            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::JsonWebKeySet`")))),
334        }
335    } else {
336        let content = resp.text().await?;
337        let entity: Option<SetJsonWebKeySetError> = serde_json::from_str(&content).ok();
338        Err(Error::ResponseError(ResponseContent { status, content, entity }))
339    }
340}
341