diff options
Diffstat (limited to 'lib/auth-service/src/client/mod.rs')
| -rw-r--r-- | lib/auth-service/src/client/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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() + } } |
