feat(auth): Implement Google OAuth 2.0 integration with user creation and JWT generation

- Added Google OAuth controller and service to handle authentication via Google.
- Introduced DTOs for Google user and token responses.
- Updated AuthService and UsersService traits to support new Google OAuth functionality.
- Implemented logic to create a new user if they do not exist in the system after Google authentication.
- Enhanced existing user retrieval and JWT generation upon successful login.
- Added tests for Google OAuth flow, including login redirection and callback handling for both new and existing users.
- Updated environment configuration to include Google OAuth credentials.
This commit is contained in:
MythEclipse
2025-08-11 22:31:51 +07:00
parent c6a95c1231
commit cda950ed7e
22 changed files with 1144 additions and 104 deletions
+8
View File
@@ -27,6 +27,10 @@ pub struct Env {
pub minio_bucket_name: String,
pub minio_access_key: String,
pub minio_secret_key: String,
// Google OAuth 2.1
pub google_client_id: String,
pub google_client_secret: String,
pub google_redirect_url: String,
}
/// Helper to get env var with warning if not set.
@@ -74,5 +78,9 @@ pub static ENV: Lazy<Env> = Lazy::new(|| {
minio_access_key: get_env_with_warning("MINIO_ACCESS_KEY", "minio_access"),
minio_secret_key: get_env_with_warning("MINIO_SECRET_KEY", "minio_secret"),
surrealdb_url_ws: String::new(),
// Google OAuth 2.1
google_client_id: get_env_with_warning("GOOGLE_CLIENT_ID", "default_google_client_id"),
google_client_secret: get_env_with_warning("GOOGLE_CLIENT_SECRET", "default_google_client_secret"),
google_redirect_url: get_env_with_warning("GOOGLE_REDIRECT_URL", "http://localhost:8000/api/v1/auth/google/callback"),
}
});
+5 -1
View File
@@ -86,5 +86,9 @@ pub fn decode_refresh_token(
&Validation::default(),
)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR);
result
result // Explicitly return result
}
pub fn generate_jwt(user_id: &str) -> Result<String, StatusCode> {
encode_access_token(user_id.to_string())
}