aboutsummaryrefslogtreecommitdiffstats
path: root/crates/api-auth/src/client.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-04-10 23:48:24 +0200
committerrtkay123 <dev@kanjala.com>2026-04-10 23:48:24 +0200
commitf06288f156ccb8f9ebf35782a179bf57e6bc8fc2 (patch)
tree2e9eb80237094d930b4f3a54261fac0cb3350129 /crates/api-auth/src/client.rs
parentbe2af8a5fe2e58953b4970e3fed970165fc4b4ca (diff)
downloadsellershut-f06288f156ccb8f9ebf35782a179bf57e6bc8fc2.tar.bz2
sellershut-f06288f156ccb8f9ebf35782a179bf57e6bc8fc2.zip
feat(auth): get user
Diffstat (limited to 'crates/api-auth/src/client.rs')
-rw-r--r--crates/api-auth/src/client.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/crates/api-auth/src/client.rs b/crates/api-auth/src/client.rs
new file mode 100644
index 0000000..d696162
--- /dev/null
+++ b/crates/api-auth/src/client.rs
@@ -0,0 +1,58 @@
+use std::pin::Pin;
+use std::{future::Future, ops::Deref};
+
+#[cfg(not(target_arch = "wasm32"))]
+use oauth2::HttpResponse;
+use oauth2::{AsyncHttpClient, HttpClientError, HttpRequest, http};
+
+#[derive(Clone)]
+pub struct AuthHttpClient(reqwest::Client);
+
+impl Deref for AuthHttpClient {
+ type Target = reqwest::Client;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl From<reqwest::Client> for AuthHttpClient {
+ fn from(value: reqwest::Client) -> Self {
+ Self(value)
+ }
+}
+
+impl<'c> AsyncHttpClient<'c> for AuthHttpClient {
+ type Error = HttpClientError<reqwest::Error>;
+
+ #[cfg(target_arch = "wasm32")]
+ type Future = Pin<Box<dyn Future<Output = Result<HttpResponse, Self::Error>> + 'c>>;
+ #[cfg(not(target_arch = "wasm32"))]
+ type Future =
+ Pin<Box<dyn Future<Output = Result<HttpResponse, Self::Error>> + Send + Sync + 'c>>;
+
+ fn call(&'c self, request: HttpRequest) -> Self::Future {
+ Box::pin(async move {
+ let response = self
+ .0
+ .execute(request.try_into().map_err(Box::new)?)
+ .await
+ .map_err(Box::new)?;
+
+ let mut builder = http::Response::builder().status(response.status());
+
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ builder = builder.version(response.version());
+ }
+
+ for (name, value) in response.headers().iter() {
+ builder = builder.header(name, value);
+ }
+
+ builder
+ .body(response.bytes().await.map_err(Box::new)?.to_vec())
+ .map_err(HttpClientError::Http)
+ })
+ }
+}