bitwarden_core/auth/api/request/
mod.rs1#[cfg(feature = "secrets")]
2mod access_token_request;
3#[cfg(feature = "secrets")]
4pub(crate) use access_token_request::*;
5
6mod api_token_request;
7pub(crate) use api_token_request::*;
8
9#[cfg(feature = "internal")]
10mod password_token_request;
11use bitwarden_api_api::Configuration;
12#[cfg(feature = "internal")]
13pub(crate) use password_token_request::*;
14
15mod renew_token_request;
16pub(crate) use renew_token_request::*;
17
18mod auth_request_token_request;
19#[cfg(feature = "internal")]
20pub(crate) use auth_request_token_request::*;
21
22use crate::{
23 ApiError,
24 auth::{
25 api::response::{IdentityTokenResponse, parse_identity_response},
26 login::LoginError,
27 },
28};
29
30pub(crate) async fn send_identity_connect_request(
31 identity_config: &Configuration,
32 body: impl serde::Serialize,
33) -> Result<IdentityTokenResponse, LoginError> {
34 let response = identity_config
35 .client
36 .post(format!("{}/connect/token", &identity_config.base_path))
37 .header(
38 reqwest::header::CONTENT_TYPE,
39 "application/x-www-form-urlencoded; charset=utf-8",
40 )
41 .header(reqwest::header::ACCEPT, "application/json")
42 .body(serde_qs::to_string(&body).expect("Serialize should be infallible"))
43 .send()
44 .await
45 .map_err(ApiError::from)?;
46
47 let status = response.status();
48 let text = response.text().await.map_err(ApiError::from)?;
49
50 parse_identity_response(status, text)
51}