From 9b0c8c23e85930ef1128e73e06713c8a36708625 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 8 Feb 2026 13:35:04 +0200 Subject: feat: merge config --- lib/auth-service/src/client/mod.rs | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/auth-service/src/client/mod.rs (limited to 'lib/auth-service/src/client') diff --git a/lib/auth-service/src/client/mod.rs b/lib/auth-service/src/client/mod.rs new file mode 100644 index 0000000..25cf16c --- /dev/null +++ b/lib/auth-service/src/client/mod.rs @@ -0,0 +1,49 @@ +use oauth2::{AuthUrl, ClientId, ClientSecret, EndpointNotSet, EndpointSet, RedirectUrl, TokenUrl}; +use secrecy::{ExposeSecret, SecretString}; +use tracing::debug; +use url::Url; + +use crate::AuthServiceError; + +pub struct OauthClient( + oauth2::basic::BasicClient< + EndpointSet, + EndpointNotSet, + EndpointNotSet, + EndpointNotSet, + EndpointSet, + >, +); + +pub struct ClientConfig { + client_id: String, + client_secret: SecretString, + token_url: Url, + auth_url: Url, +} + +impl TryFrom for OauthClient { + type Error = AuthServiceError; + + fn try_from(value: ClientConfig) -> Result { + debug!("creating oauth client"); + Ok(Self( + oauth2::basic::BasicClient::new(ClientId::new(value.client_id)) + .set_client_secret(ClientSecret::new( + value.client_secret.expose_secret().to_string(), + )) + .set_auth_uri(AuthUrl::from_url(value.auth_url)) + .set_token_uri(TokenUrl::from_url(value.token_url)), + )) + } +} + +impl OauthClient { + #[must_use] + pub fn with_redirect_url(self, url: &Url) -> Self { + Self( + self.0 + .set_redirect_uri(RedirectUrl::from_url(url.to_owned())), + ) + } +} -- cgit v1.2.3