This Android app now fetches whitelisted URLs from a remote server using Retrofit and Gson. The app securely authenticates with JWT tokens and dynamically loads the whitelist on startup.
The app connects to: http://192.168.2.244:5001
You can change this in: app/src/main/java/com/secure/privacyfirst/network/RetrofitClient.kt
- POST /api/login - Get JWT token
- GET /api/whitelist/ - Fetch whitelisted URLs
- POST /api/whitelist/add - Add new URL (admin)
- PUT /api/whitelist/update - Update URL (admin)
- DELETE /api/whitelist/delete - Delete URL (admin)
[versions]
retrofit = "2.11.0"
okhttp = "4.12.0"
gson = "2.11.0"
[libraries]
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }
okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }implementation libs.retrofit
implementation libs.retrofit.converter.gson
implementation libs.okhttp.logging
implementation libs.gson-
ApiModels.kt - Request and response data classes
LoginRequest,LoginResponseWhitelistResponseAddUrlRequest,UpdateUrlRequest,DeleteUrlRequest
-
ApiService.kt - Retrofit interface
- Defines all API endpoints
- Uses suspend functions for coroutines
-
RetrofitClient.kt - Singleton Retrofit instance
- Configures OkHttp with logging
- Sets base URL and timeouts
- Adds Gson converter
-
TokenManager.kt - JWT token management
- Securely stores token using DataStore
- Manages token expiry
- Provides auth headers
-
WhitelistRepository.kt - Business logic
- Handles login and token refresh
- Fetches whitelist from server
- Manages CRUD operations for URLs
The WebViewScreen.kt now:
- Fetches whitelist on app start using
LaunchedEffect - Automatically logs in and retrieves JWT token
- Uses server whitelist for URL validation
- Falls back to hardcoded list if server is unavailable
- Shows toast notifications for load status
The app allows HTTP traffic ONLY for the API server IP:
network_security_config.xml:
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.2.244</domain>
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>All banking sites remain HTTPS-only for security.
-
App Startup
- WebView screen loads
- Automatically calls
whitelistRepository.getWhitelist() - If no token or expired, automatically calls
login() - Stores JWT token securely in DataStore
-
URL Loading
- User navigates to a URL
- App checks if URL host matches any whitelisted domain
- If yes: loads URL
- If no: shows warning dialog
-
Daily Refresh (Recommended)
- Implement periodic refresh using WorkManager
- Fetch updated whitelist every 24 hours
- Update local cache
✅ JWT Authentication - Bearer token for all API calls ✅ Secure Storage - Tokens stored in encrypted DataStore ✅ Token Expiry - Automatic re-authentication when expired ✅ HTTPS Enforcement - Banking sites always use HTTPS ✅ Cleartext Restricted - Only API server allows HTTP
- Username:
admin - Password:
pass123
Update these in WhitelistRepository.kt or use environment variables.
- Ensure server is running at
http://192.168.2.244:5001 - Test login:
POST http://192.168.2.244:5001/api/login - Launch app and check Logcat for:
- "Fetching whitelist from server..."
- "Login successful, token saved"
- "Whitelist loaded: X URLs"
Tag: WebViewScreen
Tag: WhitelistRepository
Tag: TokenManager
- Check server is running
- Verify IP address is correct (192.168.2.244)
- Ensure phone is on same network
- Check firewall settings
- Login may have failed
- Check admin credentials
- Verify JWT_SECRET is set on server
- Verify network_security_config.xml includes server IP
- Check usesCleartextTraffic settings
-
WorkManager Integration
- Schedule daily whitelist refresh
- Background sync when app is closed
-
Caching Strategy
- Cache whitelist in Room database
- Offline support with last known whitelist
-
Admin Panel
- Add UI for managing whitelist
- CRUD operations from within app
-
Analytics
- Track blocked URLs
- Monitor whitelist usage
app/src/main/java/com/secure/privacyfirst/network/ApiModels.ktapp/src/main/java/com/secure/privacyfirst/network/ApiService.ktapp/src/main/java/com/secure/privacyfirst/network/RetrofitClient.ktapp/src/main/java/com/secure/privacyfirst/network/TokenManager.ktapp/src/main/java/com/secure/privacyfirst/network/WhitelistRepository.kt
gradle/libs.versions.toml- Added Retrofit, Gson, OkHttp versionsapp/build.gradle- Added dependenciesapp/src/main/res/xml/network_security_config.xml- Allow cleartext for API serverapp/src/main/java/com/secure/privacyfirst/ui/screens/WebViewScreen.kt- Integrated whitelist fetching
- Retrofit: 2.11.0 (Latest stable as of Nov 2024)
- OkHttp: 4.12.0 (Latest stable)
- Gson: 2.11.0 (Latest stable)
- Kotlin: 2.2.21
- Compose: 2025.11.00
All versions verified as latest stable releases.