clerk_fapi_rs/apis/
saml_api.rs

1/*
2 * Clerk Frontend API
3 *
4 * The Clerk REST Frontend API, meant to be accessed from a browser or native environment.  This is a Form Based API and all the data must be sent and formatted according to the `application/x-www-form-urlencoded` content type.  ### Versions  When the API changes in a way that isn't compatible with older versions, a new version is released. Each version is identified by its release date, e.g. `2021-02-05`. For more information, please see [Clerk API Versions](https://clerk.com/docs/backend-requests/versioning/overview).  ### Using the Try It Console  The `Try It` feature of the docs only works for **Development Instances** when using the `DevBrowser` security scheme. To use it, first generate a dev instance token from the `/v1/dev_browser` endpoint.  Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`acs`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AcsError {
20    Status400(models::ClerkErrors),
21    Status401(models::ClerkErrors),
22    Status403(models::ClerkErrors),
23    Status404(models::ClerkErrors),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`saml_metadata`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum SamlMetadataError {
31    Status400(models::ClerkErrors),
32    Status404(models::ClerkErrors),
33    UnknownValue(serde_json::Value),
34}
35
36/// The SAML Assertion Consumer Service (ACS) endpoint, which processes SAML Responses by the IdP.
37pub async fn acs(
38    configuration: &configuration::Configuration,
39    saml_connection_id: &str,
40) -> Result<(), Error<AcsError>> {
41    // add a prefix to parameters to efficiently prevent name collisions
42    let p_path_saml_connection_id = saml_connection_id;
43
44    let uri_str = format!(
45        "{}/v1/saml/acs/{saml_connection_id}",
46        configuration.base_path,
47        saml_connection_id = crate::apis::urlencode(p_path_saml_connection_id)
48    );
49    let mut req_builder = configuration
50        .client
51        .request(reqwest::Method::POST, &uri_str);
52
53    if let Some(ref apikey) = configuration.api_key {
54        let key = apikey.key.clone();
55        let value = match apikey.prefix {
56            Some(ref prefix) => format!("{prefix} {key}"),
57            None => key,
58        };
59        req_builder = req_builder.query(&[("__dev_session", value)]);
60    }
61    if let Some(ref user_agent) = configuration.user_agent {
62        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
63    }
64
65    let req = req_builder.build()?;
66    let resp = configuration.client.execute(req).await?;
67
68    let status = resp.status();
69
70    if !status.is_client_error() && !status.is_server_error() {
71        Ok(())
72    } else {
73        let content = resp.text().await?;
74        let entity: Option<AcsError> = serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent {
76            status,
77            content,
78            entity,
79        }))
80    }
81}
82
83/// The Service Provider's SAML metadata
84pub async fn saml_metadata(
85    configuration: &configuration::Configuration,
86    saml_connection_id: &str,
87) -> Result<(), Error<SamlMetadataError>> {
88    // add a prefix to parameters to efficiently prevent name collisions
89    let p_path_saml_connection_id = saml_connection_id;
90
91    let uri_str = format!(
92        "{}/v1/saml/metadata/{saml_connection_id}.xml",
93        configuration.base_path,
94        saml_connection_id = crate::apis::urlencode(p_path_saml_connection_id)
95    );
96    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98    if let Some(ref apikey) = configuration.api_key {
99        let key = apikey.key.clone();
100        let value = match apikey.prefix {
101            Some(ref prefix) => format!("{prefix} {key}"),
102            None => key,
103        };
104        req_builder = req_builder.query(&[("__dev_session", value)]);
105    }
106    if let Some(ref user_agent) = configuration.user_agent {
107        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108    }
109
110    let req = req_builder.build()?;
111    let resp = configuration.client.execute(req).await?;
112
113    let status = resp.status();
114
115    if !status.is_client_error() && !status.is_server_error() {
116        Ok(())
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<SamlMetadataError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent {
121            status,
122            content,
123            entity,
124        }))
125    }
126}