From 6cd2f96370da7f231d437312f74652f7d181ecd4 Mon Sep 17 00:00:00 2001 From: BakerNet Date: Thu, 19 Jun 2025 10:42:51 -0700 Subject: [PATCH] Remove Reddit OAuth option --- .env.example | 2 -- web-auth/src/auth.rs | 6 ------ web-auth/src/lib.rs | 1 - web-auth/src/users.rs | 47 +----------------------------------------- web/src/app/auth.rs | 8 ------- web/src/app/login.rs | 1 - web/src/backend/app.rs | 4 ---- 7 files changed, 1 insertion(+), 68 deletions(-) diff --git a/.env.example b/.env.example index 3ed1d23..50d5673 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,6 @@ DATABASE_URL=sqlite:db/mines.db GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= -REDDIT_CLIENT_ID= -REDDIT_CLIENT_SECRET= GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= REDIRECT_HOST=http://localhost:3000 # 8080 for built docker version diff --git a/web-auth/src/auth.rs b/web-auth/src/auth.rs index 92cc667..cd1728e 100644 --- a/web-auth/src/auth.rs +++ b/web-auth/src/auth.rs @@ -37,12 +37,6 @@ pub fn oauth_client(target: OAuthTarget) -> Result { "https://accounts.google.com/o/oauth2/v2/auth", "https://oauth2.googleapis.com/token", ), - OAuthTarget::Reddit => ( - "REDDIT_CLIENT_ID", - "REDDIT_CLIENT_SECRET", - "https://www.reddit.com/api/v1/authorize", - "https://www.reddit.com/api/v1/access_token", - ), OAuthTarget::Github => ( "GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET", diff --git a/web-auth/src/lib.rs b/web-auth/src/lib.rs index 6907960..a7b26b8 100644 --- a/web-auth/src/lib.rs +++ b/web-auth/src/lib.rs @@ -20,7 +20,6 @@ pub use users::{AuthSession, Backend}; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum OAuthTarget { Google, - Reddit, Github, } diff --git a/web-auth/src/users.rs b/web-auth/src/users.rs index 2721c88..90b8a7f 100644 --- a/web-auth/src/users.rs +++ b/web-auth/src/users.rs @@ -28,11 +28,6 @@ struct GoogleUserInfo { email: String, } -#[derive(Debug, Deserialize)] -struct RedditUserInfo { - name: String, -} - #[derive(Debug, Deserialize)] struct GithubUserInfo { login: String, @@ -54,22 +49,15 @@ pub enum BackendError { pub struct Backend { db: SqlitePool, google_client: SpecialClient, - reddit_client: SpecialClient, github_client: SpecialClient, http_client: reqwest::Client, } impl Backend { - pub fn new( - db: SqlitePool, - google_client: SpecialClient, - reddit_client: SpecialClient, - github_client: SpecialClient, - ) -> Self { + pub fn new(db: SqlitePool, google_client: SpecialClient, github_client: SpecialClient) -> Self { Self { db, google_client, - reddit_client, github_client, http_client: ClientBuilder::new() .redirect(reqwest::redirect::Policy::none()) @@ -81,7 +69,6 @@ impl Backend { pub fn get_client(&self, target: OAuthTarget) -> &SpecialClient { match target { OAuthTarget::Google => &self.google_client, - OAuthTarget::Reddit => &self.reddit_client, OAuthTarget::Github => &self.github_client, } } @@ -98,12 +85,6 @@ impl Backend { "https://www.googleapis.com/auth/userinfo.email".to_string(), )) .url(), - OAuthTarget::Reddit => self - .reddit_client - .authorize_url(CsrfToken::new_random) - .add_extra_param("duration", "permanent") - .add_scope(Scope::new("identity".to_string())) - .url(), OAuthTarget::Github => self .github_client .authorize_url(CsrfToken::new_random) @@ -166,32 +147,6 @@ impl AuthnBackend for Backend { .map_err(Self::Error::Reqwest)?; (token_res, format!("GOOGLE:{}", user_info.email)) } - OAuthTarget::Reddit => { - // Process authorization code, expecting a token response back. - let token_res = self - .reddit_client - .exchange_code(AuthorizationCode::new(creds.creds.code)) - .request_async(&self.http_client) - .await - .map_err(Self::Error::OAuth2)?; - - // Use access token to request user info. - let user_info = self - .http_client - .get("https://oauth.reddit.com/api/v1/me") - .header(USER_AGENT.as_str(), "minesweeper-io") - .header( - AUTHORIZATION.as_str(), - format!("Bearer {}", token_res.access_token().secret()), - ) - .send() - .await - .map_err(Self::Error::Reqwest)? - .json::() - .await - .map_err(Self::Error::Reqwest)?; - (token_res, format!("REDDIT:{}", user_info.name)) - } OAuthTarget::Github => { // Process authorization code, expecting a token response back. let token_res = self diff --git a/web/src/app/auth.rs b/web/src/app/auth.rs index 06930e3..b2bd4ad 100644 --- a/web/src/app/auth.rs +++ b/web/src/app/auth.rs @@ -64,14 +64,6 @@ pub fn LoginForm(login: ServerAction, target: OAuthTarget) -> impl IntoVi "bg-blue-400 text-white hover:bg-blue-600" ), ), - OAuthTarget::Reddit => ( - "Reddit", - "Log in with Reddit", - button_class!( - "w-full max-w-xs h-8", - "bg-orange-600 text-white hover:bg-orange-800" - ), - ), OAuthTarget::Github => ( "Github", "Log in with Github", diff --git a/web/src/app/login.rs b/web/src/app/login.rs index dbac7cb..cced370 100644 --- a/web/src/app/login.rs +++ b/web/src/app/login.rs @@ -14,7 +14,6 @@ pub fn LoginView(login: ServerAction) -> impl IntoView { "Log in if you want to set your display name, keep game history, or see your game stats & trends" -
"Note: None of your personal info is checked or stored - only your username is used to identify your account" diff --git a/web/src/backend/app.rs b/web/src/backend/app.rs index 14f83da..ab5844a 100644 --- a/web/src/backend/app.rs +++ b/web/src/backend/app.rs @@ -55,7 +55,6 @@ pub fn services_router() -> Router { pub struct App { pub db: SqlitePool, pub google_client: SpecialClient, - pub reddit_client: SpecialClient, pub github_client: SpecialClient, pub session_store: SqliteStore, } @@ -103,7 +102,6 @@ impl App { dotenvy::dotenv()?; let google_client = oauth_client(OAuthTarget::Google)?; - let reddit_client = oauth_client(OAuthTarget::Reddit)?; let github_client = oauth_client(OAuthTarget::Github)?; let db_url = env::var("DATABASE_URL").expect("DATABASE_URL should be provided"); @@ -122,7 +120,6 @@ impl App { Ok(Self { db, google_client, - reddit_client, github_client, session_store, }) @@ -172,7 +169,6 @@ impl App { let backend = Backend::new( self.db.clone(), self.google_client, - self.reddit_client, self.github_client, ); let auth_service = AuthManagerLayerBuilder::new(backend, session_layer).build();