aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-02-08 13:35:04 +0200
committerrtkay123 <dev@kanjala.com>2026-02-08 13:35:04 +0200
commit9b0c8c23e85930ef1128e73e06713c8a36708625 (patch)
tree87ddb6e754f3716c8736c13d0d7832fd717e6e4c /lib
parente4aa3d837543cdc91b563da32c36cdc3b86529e9 (diff)
downloadsellershut-9b0c8c23e85930ef1128e73e06713c8a36708625.tar.bz2
sellershut-9b0c8c23e85930ef1128e73e06713c8a36708625.zip
feat: merge config
Diffstat (limited to 'lib')
-rw-r--r--lib/auth-service/Cargo.toml3
-rw-r--r--lib/auth-service/src/client/mod.rs49
-rw-r--r--lib/auth-service/src/lib.rs23
3 files changed, 64 insertions, 11 deletions
diff --git a/lib/auth-service/Cargo.toml b/lib/auth-service/Cargo.toml
index 147c2fa..8efdc57 100644
--- a/lib/auth-service/Cargo.toml
+++ b/lib/auth-service/Cargo.toml
@@ -7,5 +7,8 @@ readme.workspace = true
documentation.workspace = true
[dependencies]
+secrecy = "0.10.3"
oauth2 = "5.0.0"
thiserror.workspace = true
+tracing.workspace = true
+url = { workspace = true, features = ["serde"] }
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<ClientConfig> for OauthClient {
+ type Error = AuthServiceError;
+
+ fn try_from(value: ClientConfig) -> Result<Self, Self::Error> {
+ 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())),
+ )
+ }
+}
diff --git a/lib/auth-service/src/lib.rs b/lib/auth-service/src/lib.rs
index b93cf3f..f7b9e80 100644
--- a/lib/auth-service/src/lib.rs
+++ b/lib/auth-service/src/lib.rs
@@ -1,14 +1,15 @@
-pub fn add(left: u64, right: u64) -> u64 {
- left + right
-}
+pub mod client;
-#[cfg(test)]
-mod tests {
- use super::*;
+use thiserror::Error;
- #[test]
- fn it_works() {
- let result = add(2, 2);
- assert_eq!(result, 4);
- }
+#[derive(Error, Debug)]
+pub enum AuthServiceError {
+ #[error("invalid url provided")]
+ InvalidUrl(#[from] url::ParseError),
+ #[error("the data for key `{0}` is not available")]
+ Redaction(String),
+ #[error("invalid header (expected {expected:?}, found {found:?})")]
+ InvalidHeader { expected: String, found: String },
+ #[error("unknown data store error")]
+ Unknown,
}