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.17.2
7 * Contact: support@ory.sh
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 [`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    let local_var_configuration = configuration;
88
89    let local_var_client = &local_var_configuration.client;
90
91    let local_var_uri_str = format!("{}/oauth2/register", local_var_configuration.base_path);
92    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
96    }
97    local_var_req_builder = local_var_req_builder.json(&o_auth2_client);
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_client_error() && !local_var_status.is_server_error() {
106        serde_json::from_str(&local_var_content).map_err(Error::from)
107    } else {
108        let local_var_entity: Option<CreateOidcDynamicClientError> = 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/// 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.
115pub async fn create_verifiable_credential(configuration: &configuration::Configuration, create_verifiable_credential_request_body: Option<models::CreateVerifiableCredentialRequestBody>) -> Result<models::VerifiableCredentialResponse, Error<CreateVerifiableCredentialError>> {
116    let local_var_configuration = configuration;
117
118    let local_var_client = &local_var_configuration.client;
119
120    let local_var_uri_str = format!("{}/credentials", local_var_configuration.base_path);
121    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
122
123    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
124        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
125    }
126    local_var_req_builder = local_var_req_builder.json(&create_verifiable_credential_request_body);
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        serde_json::from_str(&local_var_content).map_err(Error::from)
136    } else {
137        let local_var_entity: Option<CreateVerifiableCredentialError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142
143/// 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.
144pub async fn delete_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteOidcDynamicClientError>> {
145    let local_var_configuration = configuration;
146
147    let local_var_client = &local_var_configuration.client;
148
149    let local_var_uri_str = format!("{}/oauth2/register/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
150    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
151
152    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154    }
155    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
156        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157    };
158
159    let local_var_req = local_var_req_builder.build()?;
160    let local_var_resp = local_var_client.execute(local_var_req).await?;
161
162    let local_var_status = local_var_resp.status();
163    let local_var_content = local_var_resp.text().await?;
164
165    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
166        Ok(())
167    } else {
168        let local_var_entity: Option<DeleteOidcDynamicClientError> = serde_json::from_str(&local_var_content).ok();
169        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
170        Err(Error::ResponseError(local_var_error))
171    }
172}
173
174/// 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/
175pub async fn discover_oidc_configuration(configuration: &configuration::Configuration, ) -> Result<models::OidcConfiguration, Error<DiscoverOidcConfigurationError>> {
176    let local_var_configuration = configuration;
177
178    let local_var_client = &local_var_configuration.client;
179
180    let local_var_uri_str = format!("{}/.well-known/openid-configuration", local_var_configuration.base_path);
181    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
182
183    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
184        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
185    }
186
187    let local_var_req = local_var_req_builder.build()?;
188    let local_var_resp = local_var_client.execute(local_var_req).await?;
189
190    let local_var_status = local_var_resp.status();
191    let local_var_content = local_var_resp.text().await?;
192
193    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
194        serde_json::from_str(&local_var_content).map_err(Error::from)
195    } else {
196        let local_var_entity: Option<DiscoverOidcConfigurationError> = serde_json::from_str(&local_var_content).ok();
197        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
198        Err(Error::ResponseError(local_var_error))
199    }
200}
201
202/// 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.
203pub async fn get_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str) -> Result<models::OAuth2Client, Error<GetOidcDynamicClientError>> {
204    let local_var_configuration = configuration;
205
206    let local_var_client = &local_var_configuration.client;
207
208    let local_var_uri_str = format!("{}/oauth2/register/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
209    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
210
211    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
212        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
213    }
214    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
215        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
216    };
217
218    let local_var_req = local_var_req_builder.build()?;
219    let local_var_resp = local_var_client.execute(local_var_req).await?;
220
221    let local_var_status = local_var_resp.status();
222    let local_var_content = local_var_resp.text().await?;
223
224    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
225        serde_json::from_str(&local_var_content).map_err(Error::from)
226    } else {
227        let local_var_entity: Option<GetOidcDynamicClientError> = serde_json::from_str(&local_var_content).ok();
228        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
229        Err(Error::ResponseError(local_var_error))
230    }
231}
232
233/// 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.
234pub async fn get_oidc_user_info(configuration: &configuration::Configuration, ) -> Result<models::OidcUserInfo, Error<GetOidcUserInfoError>> {
235    let local_var_configuration = configuration;
236
237    let local_var_client = &local_var_configuration.client;
238
239    let local_var_uri_str = format!("{}/userinfo", local_var_configuration.base_path);
240    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
241
242    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
243        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244    }
245    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
246        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
247    };
248
249    let local_var_req = local_var_req_builder.build()?;
250    let local_var_resp = local_var_client.execute(local_var_req).await?;
251
252    let local_var_status = local_var_resp.status();
253    let local_var_content = local_var_resp.text().await?;
254
255    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
256        serde_json::from_str(&local_var_content).map_err(Error::from)
257    } else {
258        let local_var_entity: Option<GetOidcUserInfoError> = serde_json::from_str(&local_var_content).ok();
259        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
260        Err(Error::ResponseError(local_var_error))
261    }
262}
263
264/// 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.
265pub async fn revoke_oidc_session(configuration: &configuration::Configuration, ) -> Result<(), Error<RevokeOidcSessionError>> {
266    let local_var_configuration = configuration;
267
268    let local_var_client = &local_var_configuration.client;
269
270    let local_var_uri_str = format!("{}/oauth2/sessions/logout", local_var_configuration.base_path);
271    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
272
273    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
274        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
275    }
276
277    let local_var_req = local_var_req_builder.build()?;
278    let local_var_resp = local_var_client.execute(local_var_req).await?;
279
280    let local_var_status = local_var_resp.status();
281    let local_var_content = local_var_resp.text().await?;
282
283    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
284        Ok(())
285    } else {
286        let local_var_entity: Option<RevokeOidcSessionError> = serde_json::from_str(&local_var_content).ok();
287        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
288        Err(Error::ResponseError(local_var_error))
289    }
290}
291
292/// 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.
293pub async fn set_oidc_dynamic_client(configuration: &configuration::Configuration, id: &str, o_auth2_client: models::OAuth2Client) -> Result<models::OAuth2Client, Error<SetOidcDynamicClientError>> {
294    let local_var_configuration = configuration;
295
296    let local_var_client = &local_var_configuration.client;
297
298    let local_var_uri_str = format!("{}/oauth2/register/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
299    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
300
301    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
302        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
303    }
304    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
305        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
306    };
307    local_var_req_builder = local_var_req_builder.json(&o_auth2_client);
308
309    let local_var_req = local_var_req_builder.build()?;
310    let local_var_resp = local_var_client.execute(local_var_req).await?;
311
312    let local_var_status = local_var_resp.status();
313    let local_var_content = local_var_resp.text().await?;
314
315    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
316        serde_json::from_str(&local_var_content).map_err(Error::from)
317    } else {
318        let local_var_entity: Option<SetOidcDynamicClientError> = serde_json::from_str(&local_var_content).ok();
319        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
320        Err(Error::ResponseError(local_var_error))
321    }
322}
323