Skip to main content

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.94
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    Status400(models::ErrorOAuth2),
63    DefaultResponse(models::ErrorOAuth2),
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`set_json_web_key_set`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum SetJsonWebKeySetError {
71    Status400(models::ErrorOAuth2),
72    DefaultResponse(models::ErrorOAuth2),
73    UnknownValue(serde_json::Value),
74}
75
76
77/// This endpoint is capable of generating JSON Web Key Sets for you. There are different strategies available, such as symmetric cryptographic keys (HS256, HS512) and asymmetric cryptographic keys (RS256, ECDSA). If the specified JSON Web Key Set does not exist, it will be created.  If the set already exists, the newly generated key is added to it and all existing keys are kept. This allows you to rotate keys: tokens signed with an older key in the set remain verifiable. Exception: when Ory Hydra is configured to use a Hardware Security Module (HSM), generating a key replaces the set, which then contains only the new key. To replace a set and all of its keys instead, use the `setJsonWebKeySet` operation (`PUT /admin/keys/{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.  While `jwks.admin_api.expose_private_keys` is disabled, responses contain public key material only, and a key with no public representation is omitted. The generated key is stored in full either way.
78pub async fn create_json_web_key_set(configuration: &configuration::Configuration, set: &str, create_json_web_key_set: models::CreateJsonWebKeySet) -> Result<models::JsonWebKeySet, Error<CreateJsonWebKeySetError>> {
79    // add a prefix to parameters to efficiently prevent name collisions
80    let p_path_set = set;
81    let p_body_create_json_web_key_set = create_json_web_key_set;
82
83    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_path_set));
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.bearer_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
92    req_builder = req_builder.json(&p_body_create_json_web_key_set);
93
94    let req = req_builder.build()?;
95    let resp = configuration.client.execute(req).await?;
96
97    let status = resp.status();
98    let content_type = resp
99        .headers()
100        .get("content-type")
101        .and_then(|v| v.to_str().ok())
102        .unwrap_or("application/octet-stream");
103    let content_type = super::ContentType::from(content_type);
104
105    if !status.is_client_error() && !status.is_server_error() {
106        let content = resp.text().await?;
107        match content_type {
108            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
109            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
110            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`")))),
111        }
112    } else {
113        let content = resp.text().await?;
114        let entity: Option<CreateJsonWebKeySetError> = serde_json::from_str(&content).ok();
115        Err(Error::ResponseError(ResponseContent { status, content, entity }))
116    }
117}
118
119/// 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.
120pub async fn delete_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str) -> Result<(), Error<DeleteJsonWebKeyError>> {
121    // add a prefix to parameters to efficiently prevent name collisions
122    let p_path_set = set;
123    let p_path_kid = kid;
124
125    let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_path_set), kid=crate::apis::urlencode(p_path_kid));
126    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
127
128    if let Some(ref user_agent) = configuration.user_agent {
129        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130    }
131    if let Some(ref token) = configuration.bearer_access_token {
132        req_builder = req_builder.bearer_auth(token.to_owned());
133    };
134
135    let req = req_builder.build()?;
136    let resp = configuration.client.execute(req).await?;
137
138    let status = resp.status();
139
140    if !status.is_client_error() && !status.is_server_error() {
141        Ok(())
142    } else {
143        let content = resp.text().await?;
144        let entity: Option<DeleteJsonWebKeyError> = serde_json::from_str(&content).ok();
145        Err(Error::ResponseError(ResponseContent { status, content, entity }))
146    }
147}
148
149/// 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.
150pub async fn delete_json_web_key_set(configuration: &configuration::Configuration, set: &str) -> Result<(), Error<DeleteJsonWebKeySetError>> {
151    // add a prefix to parameters to efficiently prevent name collisions
152    let p_path_set = set;
153
154    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_path_set));
155    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
156
157    if let Some(ref user_agent) = configuration.user_agent {
158        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
159    }
160    if let Some(ref token) = configuration.bearer_access_token {
161        req_builder = req_builder.bearer_auth(token.to_owned());
162    };
163
164    let req = req_builder.build()?;
165    let resp = configuration.client.execute(req).await?;
166
167    let status = resp.status();
168
169    if !status.is_client_error() && !status.is_server_error() {
170        Ok(())
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<DeleteJsonWebKeySetError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent { status, content, entity }))
175    }
176}
177
178/// This endpoint returns a singular JSON Web Key contained in a set. It is identified by the set and the specific key ID (kid).  While `jwks.admin_api.expose_private_keys` is disabled, responses contain public key material only, and a key with no public representation is omitted.
179pub async fn get_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str) -> Result<models::JsonWebKeySet, Error<GetJsonWebKeyError>> {
180    // add a prefix to parameters to efficiently prevent name collisions
181    let p_path_set = set;
182    let p_path_kid = kid;
183
184    let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_path_set), kid=crate::apis::urlencode(p_path_kid));
185    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
186
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190    if let Some(ref token) = configuration.bearer_access_token {
191        req_builder = req_builder.bearer_auth(token.to_owned());
192    };
193
194    let req = req_builder.build()?;
195    let resp = configuration.client.execute(req).await?;
196
197    let status = resp.status();
198    let content_type = resp
199        .headers()
200        .get("content-type")
201        .and_then(|v| v.to_str().ok())
202        .unwrap_or("application/octet-stream");
203    let content_type = super::ContentType::from(content_type);
204
205    if !status.is_client_error() && !status.is_server_error() {
206        let content = resp.text().await?;
207        match content_type {
208            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
210            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`")))),
211        }
212    } else {
213        let content = resp.text().await?;
214        let entity: Option<GetJsonWebKeyError> = serde_json::from_str(&content).ok();
215        Err(Error::ResponseError(ResponseContent { status, content, entity }))
216    }
217}
218
219/// 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.  While `jwks.admin_api.expose_private_keys` is disabled, responses contain public key material only, and a key with no public representation is omitted.
220pub async fn get_json_web_key_set(configuration: &configuration::Configuration, set: &str) -> Result<models::JsonWebKeySet, Error<GetJsonWebKeySetError>> {
221    // add a prefix to parameters to efficiently prevent name collisions
222    let p_path_set = set;
223
224    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_path_set));
225    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
226
227    if let Some(ref user_agent) = configuration.user_agent {
228        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
229    }
230    if let Some(ref token) = configuration.bearer_access_token {
231        req_builder = req_builder.bearer_auth(token.to_owned());
232    };
233
234    let req = req_builder.build()?;
235    let resp = configuration.client.execute(req).await?;
236
237    let status = resp.status();
238    let content_type = resp
239        .headers()
240        .get("content-type")
241        .and_then(|v| v.to_str().ok())
242        .unwrap_or("application/octet-stream");
243    let content_type = super::ContentType::from(content_type);
244
245    if !status.is_client_error() && !status.is_server_error() {
246        let content = resp.text().await?;
247        match content_type {
248            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
250            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`")))),
251        }
252    } else {
253        let content = resp.text().await?;
254        let entity: Option<GetJsonWebKeySetError> = serde_json::from_str(&content).ok();
255        Err(Error::ResponseError(ResponseContent { status, content, entity }))
256    }
257}
258
259/// Use this method if you do not want to let Hydra generate the JWKs for you, but instead save your own.  The key is created or updated under the `{kid}` path parameter. If the request body carries a `kid`, it must equal the path parameter, or the request is rejected with `400`. A body without a `kid` takes the path parameter as its `kid`.  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.  The response echoes the key as it was stored, including any private key material the request carried. `jwks.admin_api.expose_private_keys` governs what a read discloses and does not apply here, because this response returns only what the request already contained.  While that setting is disabled, writing a public key over the last private key of a set is rejected with `400`, because reading the set returns public keys only and writing that response back would discard the key it signs with.
260pub async fn set_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str, json_web_key: Option<models::JsonWebKey>) -> Result<models::JsonWebKey, Error<SetJsonWebKeyError>> {
261    // add a prefix to parameters to efficiently prevent name collisions
262    let p_path_set = set;
263    let p_path_kid = kid;
264    let p_body_json_web_key = json_web_key;
265
266    let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_path_set), kid=crate::apis::urlencode(p_path_kid));
267    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
268
269    if let Some(ref user_agent) = configuration.user_agent {
270        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
271    }
272    if let Some(ref token) = configuration.bearer_access_token {
273        req_builder = req_builder.bearer_auth(token.to_owned());
274    };
275    req_builder = req_builder.json(&p_body_json_web_key);
276
277    let req = req_builder.build()?;
278    let resp = configuration.client.execute(req).await?;
279
280    let status = resp.status();
281    let content_type = resp
282        .headers()
283        .get("content-type")
284        .and_then(|v| v.to_str().ok())
285        .unwrap_or("application/octet-stream");
286    let content_type = super::ContentType::from(content_type);
287
288    if !status.is_client_error() && !status.is_server_error() {
289        let content = resp.text().await?;
290        match content_type {
291            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKey`"))),
293            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`")))),
294        }
295    } else {
296        let content = resp.text().await?;
297        let entity: Option<SetJsonWebKeyError> = serde_json::from_str(&content).ok();
298        Err(Error::ResponseError(ResponseContent { status, content, entity }))
299    }
300}
301
302/// Use this method if you do not want to let Hydra generate the JWKs for you, but instead save your own.  This operation replaces the entire JSON Web Key Set: keys that exist in the set but are not part of the request body are deleted. To add a newly generated key to the set while keeping the existing keys, use the `createJsonWebKeySet` operation (`POST /admin/keys/{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.  The response echoes the key set as it was stored, including any private key material the request carried. `jwks.admin_api.expose_private_keys` governs what a read discloses and does not apply here, because this response returns only what the request already contained.  While that setting is disabled, a request that would leave the key set without a private key is rejected with `400`. Reading a key set returns public keys only, so writing that response back would discard the private keys the set signs with. Retiring one key to its public half stays possible as long as the set keeps another private key, and a key set is removed with the `deleteJsonWebKeySet` operation.
303pub async fn set_json_web_key_set(configuration: &configuration::Configuration, set: &str, json_web_key_set: Option<models::JsonWebKeySet>) -> Result<models::JsonWebKeySet, Error<SetJsonWebKeySetError>> {
304    // add a prefix to parameters to efficiently prevent name collisions
305    let p_path_set = set;
306    let p_body_json_web_key_set = json_web_key_set;
307
308    let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_path_set));
309    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
310
311    if let Some(ref user_agent) = configuration.user_agent {
312        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
313    }
314    if let Some(ref token) = configuration.bearer_access_token {
315        req_builder = req_builder.bearer_auth(token.to_owned());
316    };
317    req_builder = req_builder.json(&p_body_json_web_key_set);
318
319    let req = req_builder.build()?;
320    let resp = configuration.client.execute(req).await?;
321
322    let status = resp.status();
323    let content_type = resp
324        .headers()
325        .get("content-type")
326        .and_then(|v| v.to_str().ok())
327        .unwrap_or("application/octet-stream");
328    let content_type = super::ContentType::from(content_type);
329
330    if !status.is_client_error() && !status.is_server_error() {
331        let content = resp.text().await?;
332        match content_type {
333            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
334            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
335            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`")))),
336        }
337    } else {
338        let content = resp.text().await?;
339        let entity: Option<SetJsonWebKeySetError> = serde_json::from_str(&content).ok();
340        Err(Error::ResponseError(ResponseContent { status, content, entity }))
341    }
342}
343