Skip to content

Replace ipapi with MaxMind GeoIP2 for geolocation services#917

Merged
neozhu merged 1 commit intomainfrom
feature/replace-ipapi-with-maxmind
Nov 5, 2025
Merged

Replace ipapi with MaxMind GeoIP2 for geolocation services#917
neozhu merged 1 commit intomainfrom
feature/replace-ipapi-with-maxmind

Conversation

@neozhu
Copy link
Copy Markdown
Owner

@neozhu neozhu commented Nov 5, 2025

Overview

This PR migrates the geolocation service from free IP lookup APIs (ipapi.co and ip-api.com) to MaxMind GeoIP2 Web Services API for more reliable and accurate IP geolocation lookups.

Changes

  • ✅ Added MaxMind.GeoIP2 NuGet package (v5.3.0) to Application project
  • ✅ Removed IGeolocationService interface and GeolocationService implementation
  • ✅ Updated LoginAuditCreatedEventHandler to use MaxMind WebServiceClient directly
  • ✅ Added MaxMind configuration settings (AccountId, LicenseKey, Host) to appsettings.json
  • ✅ Updated DependencyInjection to register MaxMind WebServiceClient with HttpClient
  • ✅ Updated docker-compose.yml to include MaxMind environment variables
  • ✅ Removed dependency on free IP lookup APIs (ipapi.co, ip-api.com)
  • ✅ Updated package references (FluentValidation 12.1.0, QuestPDF 2025.7.4, Serilog.Sinks 9.0.2, MudBlazor 8.14.0)

Benefits

  • ✨ More accurate and reliable geolocation data
  • ⚡ Better performance with MaxMind's dedicated service
  • 🔒 Professional-grade IP intelligence
  • 🚀 Support for offline databases (future enhancement)

Configuration Required

Before deploying, ensure the following environment variables are set:

  • MAXMIND_ACCOUNT_ID: Your MaxMind account ID
  • MAXMIND_LICENSE_KEY: Your MaxMind license key

In appsettings.json, configure:

"MaxMind": {
  "AccountId": 0,
  "LicenseKey": "your license key",
  "Host": "geolite.info" // For GeoLite2 free tier
}

Testing

  • Tested geolocation lookup with real IP addresses
  • Verified error handling for invalid IPs
  • Confirmed configuration loading from appsettings.json
  • Validated Docker environment variable mapping

Breaking Changes

⚠️ This change requires MaxMind API credentials to be configured. Free tier (GeoLite2) is available.

Files Changed

  • src/Application/Application.csproj
  • src/Application/Common/Interfaces/IGeolocationService.cs (deleted)
  • src/Application/Features/LoginAudits/EventHandlers/LoginAuditCreatedEventHandler.cs
  • src/Infrastructure/DependencyInjection.cs
  • src/Infrastructure/Infrastructure.csproj
  • src/Infrastructure/Services/GeolocationService.cs (deleted)
  • src/Server.UI/appsettings.json
  • src/Server.UI/Server.UI.csproj
  • docker-compose.yml

Migrated from ipapi.co and ip-api.com to MaxMind GeoIP2 Web Services API
for more reliable and accurate IP geolocation lookups.

Changes:
- Added MaxMind.GeoIP2 NuGet package (v5.3.0) to Application project
- Removed IGeolocationService interface and GeolocationService implementation
- Updated LoginAuditCreatedEventHandler to use MaxMind WebServiceClient directly
- Added MaxMind configuration settings (AccountId, LicenseKey, Host) to appsettings.json
- Updated DependencyInjection to register MaxMind WebServiceClient with HttpClient
- Updated docker-compose.yml to include MaxMind environment variables
- Removed dependency on free IP lookup APIs (ipapi.co, ip-api.com)
- Updated package references (FluentValidation, QuestPDF, Serilog, MudBlazor)

Benefits:
- More accurate and reliable geolocation data
- Better performance with MaxMind's dedicated service
- Support for offline databases (future enhancement)
- Professional-grade IP intelligence
@neozhu neozhu merged commit 2e8e61c into main Nov 5, 2025
3 checks passed
@neozhu neozhu deleted the feature/replace-ipapi-with-maxmind branch November 9, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant