This document provides context and guidelines for AI coding assistants working with the Auth0.Android SDK codebase.
Auth0.Android is a native Android SDK for integrating Auth0 authentication and authorization into Android applications. The SDK provides a comprehensive solution for:
- Web-based authentication (Universal Login via Custom Tabs)
- Direct API authentication (database connections, passwordless)
- Secure credential storage with biometric protection
- Token management with automatic refresh
- Modern Android development patterns (Coroutines, AndroidX libraries)
Auth0.Android/
├── auth0/ # Main SDK library module
│ ├── src/main/java/com/auth0/android/
│ │ ├── provider/ # Browser-based auth providers
│ │ ├── authentication/ # Direct API authentication
│ │ ├── management/ # Management API client
│ │ ├── myaccount/ # My Account API client
│ │ ├── request/ # Network request abstractions
│ │ ├── result/ # Response/error handling
│ │ └── Auth0.kt # Main configuration class
│ └── src/test/ # Unit tests
├── sample/ # Demo application
├── .github/ # CI/CD workflows
├── gradle/ # Build configuration
│ ├── versioning.gradle # Version management
│ └── maven-publish.gradle # Publishing setup
└── .version # Current SDK version
- Builder Pattern: Used extensively for web based authentication flows (e.g.,
WebAuthProvider.login()) - Callback + Coroutines: Dual API support for both traditional callbacks and modern suspend functions
- Provider Architecture: Pluggable authentication providers with fallback strategies
-
WebAuthProvider (Recommended): Browser-based auth via Custom Tabs
- Uses App Links (
https://schemes) or custom URL schemes - Handles PKCE automatically
- Supports DPoP for enhanced security
- Uses App Links (
-
AuthenticationAPIClient: Direct API calls without browser
- Database connections (login/signup)
- Passwordless (email/SMS)
- Token refresh and revocation
- CredentialsManager: Basic storage with automatic refresh
- SecureCredentialsManager: Adds biometric/device credential protection with encrypted storage
- Storage abstraction via
Storageinterface (default: SharedPreferences) - Encryption using Android Keystore
- Language: Kotlin (primary), with Java interop support
- Minimum SDK: API 21 (Android 5.0)
- Target SDK: Latest stable Android version
- Testing: Robolectric for Android components, MockWebServer for HTTP
When adding or modifying APIs:
-
Dual API Support: Provide both callback and suspend function variants
// Callback style fun operation(callback: Callback<Result, Error>) // Coroutine style suspend fun operation(): Result
-
Builder Pattern: Use for WebAuthProvider operations
WebAuthProvider.login(account) .withScheme("https") .withScope("openid profile") .start(context, callback)
-
Error Handling: Use typed exceptions
AuthenticationExceptionfor auth failuresCredentialsManagerExceptionfor storage issues- All inherit from
Auth0Exception
- Unit tests for all new functionality
- Code coverage tracked via JaCoCo (target: >80%)
- Mock external dependencies (network, Android framework)
- Test both success and failure scenarios
- Create request class in
auth0/src/main/java/com/auth0/android/request/ - Implement both callback and suspend variants
- Add unit tests with mocked responses
- Update
EXAMPLES.mdwith usage example - Add integration test in sample app
Key files:
WebAuthProvider.kt: Main entry pointAuthenticationActivity.kt: Handles redirectsOAuthManager.kt: OAuth2 flow logicPKCE.kt: PKCE implementation
Key files:
CredentialsManager.kt: Basic implementationSecureCredentialsManager.kt: Biometric supportSharedPreferencesStorage.kt: Persistence layer
# Full build with tests and coverage
./gradlew clean test jacocoTestReport
# Run lint checks
./gradlew lint
# Build sample app
./gradlew sample:assembleDebug
# CI simulation (matches GitHub Actions)
./gradlew clean test jacocoTestReport lint --continue --console=plain --max-workers=1 --no-daemon.version: Single source of truth for SDK version- Read by
gradle/versioning.gradleand injected into BuildConfig
android {
defaultConfig {
manifestPlaceholders = [
auth0Domain: "YOUR_DOMAIN",
auth0Scheme: "https" // or custom scheme
]
}
}<string name="com_auth0_client_id">YOUR_CLIENT_ID</string>
<string name="com_auth0_domain">YOUR_DOMAIN</string>- AndroidX: Activity, Browser, Biometric, Lifecycle
- Kotlin Coroutines: For async operations
- OkHttp: HTTP client
- Gson: JSON serialization
- JWT: Token parsing and validation
- JUnit 4: Test framework
- Robolectric: Android unit testing
- Mockito/PowerMock: Mocking
- MockWebServer: HTTP testing
- Hamcrest: Assertions
- PKCE: Enabled by default for all OAuth flows
- DPoP: Optional enhanced token security
- Keystore: All credentials encrypted using Android Keystore
- Biometric: LocalAuthentication for secure access
- Certificate Pinning: Configurable via OkHttp interceptors
- README.md: Getting started and installation
- EXAMPLES.md: Detailed usage examples
- API docs: Generated via Dokka (KDoc comments)
- CHANGELOG.md: Release notes and breaking changes
- MIGRATION.md: Upgrade guides between major versions
- Update
.versionfile - Update
CHANGELOG.md - Create release branch
- CI runs full test suite
- Manual approval for publication
- Maven Central publication via
gradle/maven-publish.gradle
- Redirect URIs: Must match exactly between Auth0 dashboard and app configuration
- Custom Tabs: Require Chrome or Chrome Custom Tabs provider installed
- Biometric: Requires device credential fallback configuration
- Coroutines: Must use appropriate dispatcher for Android operations
- Proguard: Keep rules defined in
consumer-rules.pro
- Issues: GitHub Issues for bugs and feature requests
- Discussions: GitHub Discussions for questions
- Auth0 Community: https://community.auth0.com/
- Auth0 Support: For Auth0 account/dashboard issues
When assisting with this codebase:
- Preserve patterns: Follow existing Builder and callback/coroutine patterns
- Test coverage: Always include tests for new functionality
- Backward compatibility: Consider impact on existing users
- Documentation: Update relevant docs when changing public APIs
- Security: Never compromise security features (PKCE, encryption, etc.)
- Android compatibility: Test across Android versions (API 21+)
- Error handling: Provide clear, actionable error messages
val account = Auth0(clientId, domain)
WebAuthProvider.login(account)
.withScheme("https")
.withScope("openid profile email")
.start(context, object : Callback<Credentials, AuthenticationException> {
override fun onSuccess(result: Credentials) { /* ... */ }
override fun onFailure(error: AuthenticationException) { /* ... */ }
})val authClient = AuthenticationAPIClient(account)
authClient.login(email, password, "Username-Password-Authentication")
.start(callback)