ory_client/apis/
oidc_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_oidc_dynamic_client`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateOidcDynamicClientError {
22    Status400(models::ErrorOAuth2),
23    DefaultResponse(models::ErrorOAuth2),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`create_verifiable_credential`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CreateVerifiableCredentialError {
31    Status400(models::VerifiableCredentialPrimingResponse),
32    DefaultResponse(models::ErrorOAuth2),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`delete_oidc_dynamic_client`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteOidcDynamicClientError {
40    DefaultResponse(models::GenericError),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`discover_oidc_configuration`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum DiscoverOidcConfigurationError {
48    DefaultResponse(models::ErrorOAuth2),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`get_oidc_dynamic_client`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum GetOidcDynamicClientError {
56    DefaultResponse(models::ErrorOAuth2),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_oidc_user_info`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetOidcUserInfoError {
64    DefaultResponse(models::ErrorOAuth2),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`revoke_oidc_session`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum RevokeOidcSessionError {
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`set_oidc_dynamic_client`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum SetOidcDynamicClientError {
79    Status404(models::ErrorOAuth2),
80    DefaultResponse(models::ErrorOAuth2),
81    UnknownValue(serde_json::Value),
82}
83
84
85/// This endpoint behaves like the administrative counterpart (`createOAuth2Client`) but is capable of facing the public internet directly and can be used in self-service. It implements the OpenID Connect Dynamic Client Registration Protocol. This feature needs to be enabled in the configuration. This endpoint is disabled by default. It can be enabled by an administrator.  Please note that using this endpoint you are not able to choose the `client_secret` nor the `client_id` as those values will be server generated when specifying `token_endpoint_auth_method` as `client_secret_basic` or `client_secret_post`.  The `client_secret` will be returned in the response and you will not be able to retrieve it later on. Write the secret down and keep it somewhere safe.
86pub async fn create_oidc_dynamic_client(configuration: &configuration::Configuration, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<CreateOidcDynamicClientError>> {
87    // add a prefix to parameters to efficiently prevent name collisions
88    let p_o_auth2_client = o_auth2_client;
89
90    let uri_str = format!("{}/oauth2/register", configuration.base_path);
91    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
92
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96    req_builder = req_builder.json(&p_o_auth2_client);
97
98    let req = req_builder.build()?;
99    let resp = configuration.client.execute(req).await?;
100
101    let status = resp.status();
102    let content_type = resp
103        .headers()
104        .get("content-type")
105        .and_then(|v| v.to_str().ok())
106        .unwrap_or("application/octet-stream");
107    let content_type = super::ContentType::from(content_type);
108
109    if !status.is_client_error() && !status.is_server_error() {
110        let content = resp.text().await?;
111        match content_type {
112            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
114            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::OAuth2Client`")))),
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<CreateOidcDynamicClientError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
120    }
121}
122
123/// This endpoint creates a verifiable credential that attests that the user authenticated with the provided access token owns a certain public/private key pair.  More information can be found at https://openid.net/specs/openid-connect-userinfo-vc-1_0.html.
124pub async fn create_verifiable_credential(configuration: &configuration::Configuration, create_verifiable_credential_request_body: Option<models::CreateVerifiableCredentialRequestBody>) -> Result<models::VerifiableCredentialResponse, Error<CreateVerifiableCredentialError>> {
125    // add a prefix to parameters to efficiently prevent name collisions
126    let p_create_verifiable_credential_request_body = create_verifiable_credential_request_body;
127
128    let uri_str = format!("{}/credentials", configuration.base_path);
129    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
130
131    if let Some(ref user_agent) = configuration.user_agent {
132        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133    }
134    req_builder = req_builder.json(&p_create_verifiable_credential_request_body);
135
136    let req = req_builder.build()?;
137    let resp = configuration.client.execute(req).await?;
138
139    let status = resp.status();
140    let content_type = resp
141        .headers()
142        .get("content-type")
143        .and_then(|v| v.to_str().ok())
144        .unwrap_or("application/octet-stream");
145    let content_type = super::ContentType::from(content_type);
146
147    if !status.is_client_error() && !status.is_server_error() {
148        let content = resp.text().await?;
149        match content_type {
150            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerifiableCredentialResponse`"))),
152            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::VerifiableCredentialResponse`")))),
153        }
154    } else {
155        let content = resp.text().await?;
156        let entity: Option<CreateVerifiableCredentialError> = serde_json::from_str(&content).ok();
157        Err(Error::ResponseError(ResponseContent { status, content, entity }))
158    }
159}
160
161/// This endpoint behaves like the administrative counterpart (`deleteOAuth2Client`) but is capable of facing the public internet directly and can be used in self-service. It implements the OpenID Connect Dynamic Client Registration Protocol. This feature needs to be enabled in the configuration. This endpoint is disabled by default. It can be enabled by an administrator.  To use this endpoint, you will need to present the client's authentication credentials. If the OAuth2 Client uses the Token Endpoint Authentication Method `client_secret_post`, you need to present the client secret in the URL query. If it uses `client_secret_basic`, present the Client ID and the Client Secret in the Authorization header.  OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.
162pub async fn delete_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteOidcDynamicClientError>> {
163    // add a prefix to parameters to efficiently prevent name collisions
164    let p_id = id;
165
166    let uri_str = format!("{}/oauth2/register/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
167    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref token) = configuration.bearer_access_token {
173        req_builder = req_builder.bearer_auth(token.to_owned());
174    };
175
176    let req = req_builder.build()?;
177    let resp = configuration.client.execute(req).await?;
178
179    let status = resp.status();
180
181    if !status.is_client_error() && !status.is_server_error() {
182        Ok(())
183    } else {
184        let content = resp.text().await?;
185        let entity: Option<DeleteOidcDynamicClientError> = serde_json::from_str(&content).ok();
186        Err(Error::ResponseError(ResponseContent { status, content, entity }))
187    }
188}
189
190/// A mechanism for an OpenID Connect Relying Party to discover the End-User's OpenID Provider and obtain information needed to interact with it, including its OAuth 2.0 endpoint locations.  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/
191pub async fn discover_oidc_configuration(configuration: &configuration::Configuration, ) -> Result<models::OidcConfiguration, Error<DiscoverOidcConfigurationError>> {
192
193    let uri_str = format!("{}/.well-known/openid-configuration", configuration.base_path);
194    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
195
196    if let Some(ref user_agent) = configuration.user_agent {
197        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
198    }
199
200    let req = req_builder.build()?;
201    let resp = configuration.client.execute(req).await?;
202
203    let status = resp.status();
204    let content_type = resp
205        .headers()
206        .get("content-type")
207        .and_then(|v| v.to_str().ok())
208        .unwrap_or("application/octet-stream");
209    let content_type = super::ContentType::from(content_type);
210
211    if !status.is_client_error() && !status.is_server_error() {
212        let content = resp.text().await?;
213        match content_type {
214            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
215            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OidcConfiguration`"))),
216            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::OidcConfiguration`")))),
217        }
218    } else {
219        let content = resp.text().await?;
220        let entity: Option<DiscoverOidcConfigurationError> = serde_json::from_str(&content).ok();
221        Err(Error::ResponseError(ResponseContent { status, content, entity }))
222    }
223}
224
225/// This endpoint behaves like the administrative counterpart (`getOAuth2Client`) but is capable of facing the public internet directly and can be used in self-service. It implements the OpenID Connect Dynamic Client Registration Protocol.  To use this endpoint, you will need to present the client's authentication credentials. If the OAuth2 Client uses the Token Endpoint Authentication Method `client_secret_post`, you need to present the client secret in the URL query. If it uses `client_secret_basic`, present the Client ID and the Client Secret in the Authorization header.
226pub async fn get_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str) -> Result<models::OAuth2Client, Error<GetOidcDynamicClientError>> {
227    // add a prefix to parameters to efficiently prevent name collisions
228    let p_id = id;
229
230    let uri_str = format!("{}/oauth2/register/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
231    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
232
233    if let Some(ref user_agent) = configuration.user_agent {
234        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
235    }
236    if let Some(ref token) = configuration.bearer_access_token {
237        req_builder = req_builder.bearer_auth(token.to_owned());
238    };
239
240    let req = req_builder.build()?;
241    let resp = configuration.client.execute(req).await?;
242
243    let status = resp.status();
244    let content_type = resp
245        .headers()
246        .get("content-type")
247        .and_then(|v| v.to_str().ok())
248        .unwrap_or("application/octet-stream");
249    let content_type = super::ContentType::from(content_type);
250
251    if !status.is_client_error() && !status.is_server_error() {
252        let content = resp.text().await?;
253        match content_type {
254            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
256            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::OAuth2Client`")))),
257        }
258    } else {
259        let content = resp.text().await?;
260        let entity: Option<GetOidcDynamicClientError> = serde_json::from_str(&content).ok();
261        Err(Error::ResponseError(ResponseContent { status, content, entity }))
262    }
263}
264
265/// This endpoint returns the payload of the ID Token, including `session.id_token` values, of the provided OAuth 2.0 Access Token's consent request.  In the case of authentication error, a WWW-Authenticate header might be set in the response with more information about the error. See [the spec](https://datatracker.ietf.org/doc/html/rfc6750#section-3) for more details about header format.
266pub async fn get_oidc_user_info(configuration: &configuration::Configuration, ) -> Result<models::OidcUserInfo, Error<GetOidcUserInfoError>> {
267
268    let uri_str = format!("{}/userinfo", configuration.base_path);
269    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
270
271    if let Some(ref user_agent) = configuration.user_agent {
272        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
273    }
274    if let Some(ref token) = configuration.oauth_access_token {
275        req_builder = req_builder.bearer_auth(token.to_owned());
276    };
277
278    let req = req_builder.build()?;
279    let resp = configuration.client.execute(req).await?;
280
281    let status = resp.status();
282    let content_type = resp
283        .headers()
284        .get("content-type")
285        .and_then(|v| v.to_str().ok())
286        .unwrap_or("application/octet-stream");
287    let content_type = super::ContentType::from(content_type);
288
289    if !status.is_client_error() && !status.is_server_error() {
290        let content = resp.text().await?;
291        match content_type {
292            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
293            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OidcUserInfo`"))),
294            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::OidcUserInfo`")))),
295        }
296    } else {
297        let content = resp.text().await?;
298        let entity: Option<GetOidcUserInfoError> = serde_json::from_str(&content).ok();
299        Err(Error::ResponseError(ResponseContent { status, content, entity }))
300    }
301}
302
303/// This endpoint initiates and completes user logout at the Ory OAuth2 & OpenID provider 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  Back-channel logout is performed asynchronously and does not affect logout flow.
304pub async fn revoke_oidc_session(configuration: &configuration::Configuration, ) -> Result<(), Error<RevokeOidcSessionError>> {
305
306    let uri_str = format!("{}/oauth2/sessions/logout", configuration.base_path);
307    let mut req_builder = configuration.client.request(reqwest::Method::GET, &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
313    let req = req_builder.build()?;
314    let resp = configuration.client.execute(req).await?;
315
316    let status = resp.status();
317
318    if !status.is_client_error() && !status.is_server_error() {
319        Ok(())
320    } else {
321        let content = resp.text().await?;
322        let entity: Option<RevokeOidcSessionError> = serde_json::from_str(&content).ok();
323        Err(Error::ResponseError(ResponseContent { status, content, entity }))
324    }
325}
326
327/// This endpoint behaves like the administrative counterpart (`setOAuth2Client`) but is capable of facing the public internet directly to be used by third parties. It implements the OpenID Connect Dynamic Client Registration Protocol.  This feature is disabled per default. It can be enabled by a system administrator.  If you pass `client_secret` the secret is used, otherwise the existing secret is used. If set, the secret is echoed in the response. It is not possible to retrieve it later on.  To use this endpoint, you will need to present the client's authentication credentials. If the OAuth2 Client uses the Token Endpoint Authentication Method `client_secret_post`, you need to present the client secret in the URL query. If it uses `client_secret_basic`, present the Client ID and the Client Secret in the Authorization header.  OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.
328pub async fn set_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<SetOidcDynamicClientError>> {
329    // add a prefix to parameters to efficiently prevent name collisions
330    let p_id = id;
331    let p_o_auth2_client = o_auth2_client;
332
333    let uri_str = format!("{}/oauth2/register/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
334    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
335
336    if let Some(ref user_agent) = configuration.user_agent {
337        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
338    }
339    if let Some(ref token) = configuration.bearer_access_token {
340        req_builder = req_builder.bearer_auth(token.to_owned());
341    };
342    req_builder = req_builder.json(&p_o_auth2_client);
343
344    let req = req_builder.build()?;
345    let resp = configuration.client.execute(req).await?;
346
347    let status = resp.status();
348    let content_type = resp
349        .headers()
350        .get("content-type")
351        .and_then(|v| v.to_str().ok())
352        .unwrap_or("application/octet-stream");
353    let content_type = super::ContentType::from(content_type);
354
355    if !status.is_client_error() && !status.is_server_error() {
356        let content = resp.text().await?;
357        match content_type {
358            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
359            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OAuth2Client`"))),
360            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::OAuth2Client`")))),
361        }
362    } else {
363        let content = resp.text().await?;
364        let entity: Option<SetOidcDynamicClientError> = serde_json::from_str(&content).ok();
365        Err(Error::ResponseError(ResponseContent { status, content, entity }))
366    }
367}
368