diff --git a/backend/src/services/oauth_service.rs b/backend/src/services/oauth_service.rs index 8efada4..2dc7dba 100644 --- a/backend/src/services/oauth_service.rs +++ b/backend/src/services/oauth_service.rs @@ -1,7 +1,5 @@ -use oauth2::{ - basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl, - AuthorizationCode, TokenResponse, Scope, CsrfToken, -}; +use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl, AuthorizationCode, TokenResponse, Scope, CsrfToken, Client, StandardRevocableToken, EndpointSet, EndpointNotSet}; +use oauth2::basic::{BasicErrorResponse, BasicRevocationErrorResponse, BasicTokenIntrospectionResponse, BasicTokenResponse}; use reqwest::Client as HttpClient; use sea_orm::{DatabaseConnection, EntityTrait, ColumnTrait, QueryFilter, ActiveModelTrait, Set}; use serde::Deserialize; @@ -34,11 +32,7 @@ impl OAuthService { let redirect_url = std::env::var("GOOGLE_REDIRECT_URL") .unwrap_or_else(|_| "http://localhost:8080/api/auth/google/callback".to_string()); - let client = BasicClient::new(ClientId::new(client_id)) - .set_client_secret(ClientSecret::new(client_secret)) - .set_auth_uri(AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap()) - .set_token_uri(TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap()) - .set_redirect_uri(RedirectUrl::new(redirect_url).unwrap()); + let client = Self::getClient(client_id, client_secret, redirect_url); let (auth_url, csrf_token) = client .authorize_url(CsrfToken::new_random) @@ -58,11 +52,7 @@ impl OAuthService { let redirect_url = std::env::var("GOOGLE_REDIRECT_URL") .unwrap_or_else(|_| "http://localhost:8080/api/auth/google/callback".to_string()); - let client = BasicClient::new(ClientId::new(client_id)) - .set_client_secret(ClientSecret::new(client_secret)) - .set_auth_uri(AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap()) - .set_token_uri(TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap()) - .set_redirect_uri(RedirectUrl::new(redirect_url).unwrap()); + let client = Self::getClient(client_id, client_secret, redirect_url); let http_client = oauth2::reqwest::ClientBuilder::new() .build() @@ -77,6 +67,23 @@ impl OAuthService { Ok(token.access_token().secret().clone()) } + fn getClient(client_id: String, client_secret: String, redirect_url: String) -> Client { + BasicClient::new(ClientId::new(client_id)) + .set_client_secret(ClientSecret::new(client_secret)) + .set_auth_uri(AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap()) + .set_token_uri(TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap()) + .set_redirect_uri(RedirectUrl::new(redirect_url).unwrap()) + } + pub async fn get_user_info(&self, access_token: &str) -> Result { let response = self.http_client .get("https://www.googleapis.com/oauth2/v2/userinfo") diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4148a64..e7e6a72 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -16,6 +16,7 @@ "react": "^19.2.0", "react-dom": "^19.2.0", "react-i18next": "^16.5.3", + "react-icons": "^5.5.0", "react-router-dom": "^7.10.1", "zustand": "^5.0.9" }, @@ -3819,6 +3820,15 @@ } } }, + "node_modules/react-icons": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.5.0.tgz", + "integrity": "sha512-MEFcXdkP3dLo8uumGI5xN3lDFNsRtrjbOEKDLD7yv76v4wpnEq2Lt2qeHaQOr34I/wPN3s3+N08WkQ+CW37Xiw==", + "license": "MIT", + "peerDependencies": { + "react": "*" + } + }, "node_modules/react-refresh": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.18.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 7d0a8f6..a1cffde 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -18,6 +18,7 @@ "react": "^19.2.0", "react-dom": "^19.2.0", "react-i18next": "^16.5.3", + "react-icons": "^5.5.0", "react-router-dom": "^7.10.1", "zustand": "^5.0.9" }, diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index 70f644d..21f3932 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { authApi } from '../api/client'; import { Loader2, Wallet } from 'lucide-react'; +import { FcGoogle } from 'react-icons/fc'; export default function Login() { const { t } = useTranslation(); @@ -53,24 +54,7 @@ export default function Login() { ) : ( <> - - - - - - + {t('login.googleButton')} )} @@ -79,4 +63,4 @@ export default function Login() { ); -} \ No newline at end of file +}