qcs_api/apis/
authentication_api.rs

1/*
2 * Rigetti QCS API
3 *
4 * # Introduction  This is the documentation for the Rigetti QCS HTTP API.  You can find out more about Rigetti at [https://rigetti.com](https://rigetti.com), and also interact with QCS via the web at [https://qcs.rigetti.com](https://qcs.rigetti.com).  This API is documented in **OpenAPI format** and so is compatible with the dozens of language-specific client generators available [here](https://github.com/OpenAPITools/openapi-generator) and elsewhere on the web.  # Principles  This API follows REST design principles where appropriate, and otherwise an HTTP RPC paradigm. We adhere to the Google [API Improvement Proposals](https://google.aip.dev/general) where reasonable to provide a consistent, intuitive developer experience. HTTP response codes match their specifications, and error messages fit a common format.  # Authentication  All access to the QCS API requires OAuth2 authentication provided by Okta. You can request access [here](https://www.rigetti.com/get-quantum). Once you have a user account, you can download your access token from QCS [here](https://qcs.rigetti.com/auth/token).   That access token is valid for 24 hours after issuance. The value of `access_token` within the JSON file is the token used for authentication (don't use the entire JSON file).  Authenticate requests using the `Authorization` header and a `Bearer` prefix:  ``` curl --header \"Authorization: Bearer eyJraW...Iow\" ```  # Quantum Processor Access  Access to the quantum processors themselves is not yet provided directly by this HTTP API, but is instead performed over ZeroMQ/[rpcq](https://gitlab.com/rigetti/rpcq). Until that changes, we suggest using [pyquil](https://gitlab.com/rigetti/pyquil) to build and execute quantum programs via the Legacy API.  # Legacy API  Our legacy HTTP API remains accessible at https://forest-server.qcs.rigetti.com, and it shares a source of truth with this API's services. You can use either service with the same user account and means of authentication. We strongly recommend using the API documented here, as the legacy API is on the path to deprecation.
5 *
6 * The version of the OpenAPI document: 2020-07-31
7 * Contact: support@rigetti.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`auth_email_password_reset_token`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AuthEmailPasswordResetTokenError {
20    Status422(crate::models::Error),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`auth_get_user`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum AuthGetUserError {
28    Status401(crate::models::Error),
29    Status404(crate::models::Error),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`auth_reset_password`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum AuthResetPasswordError {
37    Status401(crate::models::Error),
38    Status422(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`auth_reset_password_with_token`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum AuthResetPasswordWithTokenError {
46    Status404(crate::models::Error),
47    Status422(crate::models::Error),
48    UnknownValue(serde_json::Value),
49}
50
51/// Send a password reset link to the provided email address, if that email matches a registered user.
52pub async fn auth_email_password_reset_token(
53    configuration: &configuration::Configuration,
54    auth_email_password_reset_token_request: Option<
55        crate::models::AuthEmailPasswordResetTokenRequest,
56    >,
57) -> Result<(), Error<AuthEmailPasswordResetTokenError>> {
58    let local_var_configuration = configuration;
59
60    let local_var_client = &local_var_configuration.client;
61
62    let local_var_uri_str = format!(
63        "{}/v1/auth:emailPasswordResetToken",
64        local_var_configuration.base_path
65    );
66    let mut local_var_req_builder =
67        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
68
69    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
70        local_var_req_builder =
71            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    local_var_req_builder = local_var_req_builder.json(&auth_email_password_reset_token_request);
74
75    let local_var_req = local_var_req_builder.build()?;
76    let local_var_resp = local_var_client.execute(local_var_req).await?;
77
78    let local_var_status = local_var_resp.status();
79    let local_var_content = local_var_resp.text().await?;
80
81    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82        Ok(())
83    } else {
84        let local_var_entity: Option<AuthEmailPasswordResetTokenError> =
85            serde_json::from_str(&local_var_content).ok();
86        let local_var_error = ResponseContent {
87            status: local_var_status,
88            content: local_var_content,
89            entity: local_var_entity,
90        };
91        Err(Error::ResponseError(local_var_error))
92    }
93}
94
95/// Retrieve the profile of the authenticated user.
96pub async fn auth_get_user(
97    configuration: &configuration::Configuration,
98) -> Result<crate::models::User, Error<AuthGetUserError>> {
99    let local_var_configuration = configuration;
100
101    let local_var_client = &local_var_configuration.client;
102
103    let local_var_uri_str = format!("{}/v1/auth:getUser", local_var_configuration.base_path);
104    let mut local_var_req_builder =
105        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
106
107    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
108        local_var_req_builder =
109            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
112        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113    };
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        serde_json::from_str(&local_var_content).map_err(Error::from)
123    } else {
124        let local_var_entity: Option<AuthGetUserError> =
125            serde_json::from_str(&local_var_content).ok();
126        let local_var_error = ResponseContent {
127            status: local_var_status,
128            content: local_var_content,
129            entity: local_var_entity,
130        };
131        Err(Error::ResponseError(local_var_error))
132    }
133}
134
135/// Reset the password using the user's existing password. Note, this is an authenticated route.
136pub async fn auth_reset_password(
137    configuration: &configuration::Configuration,
138    auth_reset_password_request: crate::models::AuthResetPasswordRequest,
139) -> Result<(), Error<AuthResetPasswordError>> {
140    let local_var_configuration = configuration;
141
142    let local_var_client = &local_var_configuration.client;
143
144    let local_var_uri_str = format!(
145        "{}/v1/auth:resetPassword",
146        local_var_configuration.base_path
147    );
148    let mut local_var_req_builder =
149        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152        local_var_req_builder =
153            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    local_var_req_builder = local_var_req_builder.json(&auth_reset_password_request);
159
160    let local_var_req = local_var_req_builder.build()?;
161    let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163    let local_var_status = local_var_resp.status();
164    let local_var_content = local_var_resp.text().await?;
165
166    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167        Ok(())
168    } else {
169        let local_var_entity: Option<AuthResetPasswordError> =
170            serde_json::from_str(&local_var_content).ok();
171        let local_var_error = ResponseContent {
172            status: local_var_status,
173            content: local_var_content,
174            entity: local_var_entity,
175        };
176        Err(Error::ResponseError(local_var_error))
177    }
178}
179
180/// Complete the forgot password flow, resetting the new password in exchange for an emailed token.
181pub async fn auth_reset_password_with_token(
182    configuration: &configuration::Configuration,
183    auth_reset_password_with_token_request: crate::models::AuthResetPasswordWithTokenRequest,
184) -> Result<(), Error<AuthResetPasswordWithTokenError>> {
185    let local_var_configuration = configuration;
186
187    let local_var_client = &local_var_configuration.client;
188
189    let local_var_uri_str = format!(
190        "{}/v1/auth:resetPasswordWithToken",
191        local_var_configuration.base_path
192    );
193    let mut local_var_req_builder =
194        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
195
196    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197        local_var_req_builder =
198            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200    local_var_req_builder = local_var_req_builder.json(&auth_reset_password_with_token_request);
201
202    let local_var_req = local_var_req_builder.build()?;
203    let local_var_resp = local_var_client.execute(local_var_req).await?;
204
205    let local_var_status = local_var_resp.status();
206    let local_var_content = local_var_resp.text().await?;
207
208    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
209        Ok(())
210    } else {
211        let local_var_entity: Option<AuthResetPasswordWithTokenError> =
212            serde_json::from_str(&local_var_content).ok();
213        let local_var_error = ResponseContent {
214            status: local_var_status,
215            content: local_var_content,
216            entity: local_var_entity,
217        };
218        Err(Error::ResponseError(local_var_error))
219    }
220}