diff options
| author | rtkay123 <dev@kanjala.com> | 2026-02-09 19:33:04 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-02-09 19:33:04 +0200 |
| commit | 375da0e07f2b3e88c2f6db0e6f4565b3ad555b95 (patch) | |
| tree | dd7e302e7385c4e7cff5021178f127c693bede9d /lib | |
| parent | a9630ecdc459068ca51ee2d7be3837d609840842 (diff) | |
| download | sellershut-375da0e07f2b3e88c2f6db0e6f4565b3ad555b95.tar.bz2 sellershut-375da0e07f2b3e88c2f6db0e6f4565b3ad555b95.zip | |
feat(auth): route to provider
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/auth-service/Cargo.toml | 2 | ||||
| -rw-r--r-- | lib/auth-service/src/client/mod.rs | 16 | ||||
| -rw-r--r-- | lib/auth-service/src/lib.rs | 4 |
3 files changed, 19 insertions, 3 deletions
diff --git a/lib/auth-service/Cargo.toml b/lib/auth-service/Cargo.toml index d35d17e..c3b9be7 100644 --- a/lib/auth-service/Cargo.toml +++ b/lib/auth-service/Cargo.toml @@ -7,7 +7,7 @@ readme.workspace = true documentation.workspace = true [dependencies] -async-session = "3.0.0" +async-session.workspace = true async-trait.workspace = true oauth2 = "5.0.0" secrecy = "0.10.3" diff --git a/lib/auth-service/src/client/mod.rs b/lib/auth-service/src/client/mod.rs index 45e7e4d..45260fb 100644 --- a/lib/auth-service/src/client/mod.rs +++ b/lib/auth-service/src/client/mod.rs @@ -1,9 +1,12 @@ -use oauth2::{AuthUrl, ClientId, ClientSecret, EndpointNotSet, EndpointSet, RedirectUrl, TokenUrl}; +use oauth2::{ + AuthUrl, ClientId, ClientSecret, CsrfToken, EndpointNotSet, EndpointSet, RedirectUrl, Scope, + TokenUrl, +}; use secrecy::{ExposeSecret, SecretString}; use tracing::debug; use url::Url; -use crate::AuthServiceError; +use crate::{AuthServiceError, Provider}; #[derive(Debug, Clone)] pub struct OauthClient( @@ -16,6 +19,7 @@ pub struct OauthClient( >, ); +#[derive(Debug)] pub struct ClientConfig { client_id: String, client_secret: SecretString, @@ -63,4 +67,12 @@ impl OauthClient { .set_redirect_uri(RedirectUrl::from_url(url.to_owned())), ) } + + pub fn url_token(&self, provider: Provider) -> (Url, CsrfToken) { + let req = self.0.authorize_url(CsrfToken::new_random); + match provider { + Provider::Discord => req.add_scope(Scope::new("identify".to_string())), + } + .url() + } } diff --git a/lib/auth-service/src/lib.rs b/lib/auth-service/src/lib.rs index 308ce0f..0965f86 100644 --- a/lib/auth-service/src/lib.rs +++ b/lib/auth-service/src/lib.rs @@ -4,6 +4,10 @@ pub use service::*; use thiserror::Error; +pub enum Provider { + Discord, +} + #[derive(Error, Debug)] pub enum AuthServiceError { #[error("invalid url provided")] |
