Skip to main content

ez_token/services/http_client/
client.rs

1use miette::Result;
2use miette::{IntoDiagnostic, WrapErr};
3use oauth2::reqwest::{Client, redirect};
4
5/// Creates an HTTP client configured for OAuth2 token requests.
6///
7/// Redirects are explicitly disabled, as OAuth2 flows manage redirects
8/// at the protocol level rather than the HTTP level. Allowing automatic
9/// redirects could silently swallow authorization errors or redirect
10/// sensitive credentials to unintended endpoints.
11///
12/// # Errors
13///
14/// Returns an error if the HTTP client fails to initialize, which may
15/// occur if the underlying TLS backend cannot be loaded.
16pub fn create_http_client() -> Result<Client> {
17    Client::builder()
18        .redirect(redirect::Policy::none())
19        .build()
20        .into_diagnostic()
21        .wrap_err("Failed to initialize HTTP client")
22}