summaryrefslogtreecommitdiffstats
path: root/crates/auth-service/src/client/discord.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/auth-service/src/client/discord.rs')
-rw-r--r--crates/auth-service/src/client/discord.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/auth-service/src/client/discord.rs b/crates/auth-service/src/client/discord.rs
new file mode 100644
index 0000000..9217684
--- /dev/null
+++ b/crates/auth-service/src/client/discord.rs
@@ -0,0 +1,30 @@
+use crate::{client::OauthClient, cnfg::OauthCredentials, error::AppError};
+use anyhow::Context;
+use oauth2::{AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl, basic::BasicClient};
+
+pub fn discord_client(config: &OauthCredentials) -> Result<OauthClient, AppError> {
+ let auth_url = config.auth_url.clone().unwrap_or_else(|| {
+ "https://discord.com/api/oauth2/authorize?response_type=code".to_string()
+ });
+
+ let token_url = config
+ .token_url
+ .clone()
+ .unwrap_or_else(|| "https://discord.com/api/oauth2/token".to_string());
+
+ let c = BasicClient::new(ClientId::new(config.client_id.to_owned()))
+ .set_client_secret(ClientSecret::new(config.client_secret.to_owned()))
+ .set_auth_uri(
+ AuthUrl::new(auth_url).context("failed to create new auth server url [discord]")?,
+ )
+ .set_redirect_uri(
+ RedirectUrl::new(config.redirect_url.to_owned())
+ .context("failed to create new redirect URL [discord]")?,
+ )
+ .set_token_uri(
+ TokenUrl::new(token_url)
+ .context("failed to create new token endpoint URL [discord]")?,
+ );
+
+ Ok(c)
+}