Skip to content

Commit 777fc0c

Browse files
authored
chore:Added AGENTS.md file for ai agents (#872)
1 parent fde302b commit 777fc0c

File tree

2 files changed

+253
-120
lines changed

2 files changed

+253
-120
lines changed

.github/copilot-instructions.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

AGENTS.md

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# AI Agent Guidelines for Auth0.Android SDK
2+
3+
This document provides context and guidelines for AI coding assistants working with the Auth0.Android SDK codebase.
4+
5+
## Project Overview
6+
7+
**Auth0.Android** is a native Android SDK for integrating Auth0 authentication and authorization into Android applications. The SDK provides a comprehensive solution for:
8+
9+
- Web-based authentication (Universal Login via Custom Tabs)
10+
- Direct API authentication (database connections, passwordless)
11+
- Secure credential storage with biometric protection
12+
- Token management with automatic refresh
13+
- Modern Android development patterns (Coroutines, AndroidX libraries)
14+
15+
## Repository Structure
16+
17+
```
18+
Auth0.Android/
19+
├── auth0/ # Main SDK library module
20+
│ ├── src/main/java/com/auth0/android/
21+
│ │ ├── provider/ # Browser-based auth providers
22+
│ │ ├── authentication/ # Direct API authentication
23+
│ │ ├── management/ # Management API client
24+
│ │ ├── myaccount/ # My Account API client
25+
│ │ ├── request/ # Network request abstractions
26+
│ │ ├── result/ # Response/error handling
27+
│ │ └── Auth0.kt # Main configuration class
28+
│ └── src/test/ # Unit tests
29+
├── sample/ # Demo application
30+
├── .github/ # CI/CD workflows
31+
├── gradle/ # Build configuration
32+
│ ├── versioning.gradle # Version management
33+
│ └── maven-publish.gradle # Publishing setup
34+
└── .version # Current SDK version
35+
```
36+
37+
## Key Technical Decisions
38+
39+
### Architecture Patterns
40+
- **Builder Pattern**: Used extensively for web based authentication flows (e.g., `WebAuthProvider.login()`)
41+
- **Callback + Coroutines**: Dual API support for both traditional callbacks and modern suspend functions
42+
- **Provider Architecture**: Pluggable authentication providers with fallback strategies
43+
44+
### Authentication Flow
45+
1. **WebAuthProvider** (Recommended): Browser-based auth via Custom Tabs
46+
- Uses App Links (`https://` schemes) or custom URL schemes
47+
- Handles PKCE automatically
48+
- Supports DPoP for enhanced security
49+
50+
2. **AuthenticationAPIClient**: Direct API calls without browser
51+
- Database connections (login/signup)
52+
- Passwordless (email/SMS)
53+
- Token refresh and revocation
54+
55+
### Credential Management Strategy
56+
- **CredentialsManager**: Basic storage with automatic refresh
57+
- **SecureCredentialsManager**: Adds biometric/device credential protection with encrypted storage
58+
- Storage abstraction via `Storage` interface (default: SharedPreferences)
59+
- Encryption using Android Keystore
60+
61+
## Development Guidelines
62+
63+
### Code Style
64+
- **Language**: Kotlin (primary), with Java interop support
65+
- **Minimum SDK**: API 21 (Android 5.0)
66+
- **Target SDK**: Latest stable Android version
67+
- **Testing**: Robolectric for Android components, MockWebServer for HTTP
68+
69+
### API Design Principles
70+
When adding or modifying APIs:
71+
72+
1. **Dual API Support**: Provide both callback and suspend function variants
73+
```kotlin
74+
// Callback style
75+
fun operation(callback: Callback<Result, Error>)
76+
77+
// Coroutine style
78+
suspend fun operation(): Result
79+
```
80+
81+
2. **Builder Pattern**: Use for WebAuthProvider operations
82+
```kotlin
83+
WebAuthProvider.login(account)
84+
.withScheme("https")
85+
.withScope("openid profile")
86+
.start(context, callback)
87+
```
88+
89+
3. **Error Handling**: Use typed exceptions
90+
- `AuthenticationException` for auth failures
91+
- `CredentialsManagerException` for storage issues
92+
- All inherit from `Auth0Exception`
93+
94+
### Testing Requirements
95+
- Unit tests for all new functionality
96+
- Code coverage tracked via JaCoCo (target: >80%)
97+
- Mock external dependencies (network, Android framework)
98+
- Test both success and failure scenarios
99+
100+
### Common Tasks
101+
102+
#### Adding a New Authentication Method
103+
1. Create request class in `auth0/src/main/java/com/auth0/android/request/`
104+
2. Implement both callback and suspend variants
105+
3. Add unit tests with mocked responses
106+
4. Update `EXAMPLES.md` with usage example
107+
5. Add integration test in sample app
108+
109+
#### Modifying Browser Authentication
110+
Key files:
111+
- `WebAuthProvider.kt`: Main entry point
112+
- `AuthenticationActivity.kt`: Handles redirects
113+
- `OAuthManager.kt`: OAuth2 flow logic
114+
- `PKCE.kt`: PKCE implementation
115+
116+
#### Updating Credential Storage
117+
Key files:
118+
- `CredentialsManager.kt`: Basic implementation
119+
- `SecureCredentialsManager.kt`: Biometric support
120+
- `SharedPreferencesStorage.kt`: Persistence layer
121+
122+
## Build & Testing Commands
123+
124+
```bash
125+
# Full build with tests and coverage
126+
./gradlew clean test jacocoTestReport
127+
128+
# Run lint checks
129+
./gradlew lint
130+
131+
# Build sample app
132+
./gradlew sample:assembleDebug
133+
134+
# CI simulation (matches GitHub Actions)
135+
./gradlew clean test jacocoTestReport lint --continue --console=plain --max-workers=1 --no-daemon
136+
```
137+
138+
## Configuration Files
139+
140+
### Version Management
141+
- **`.version`**: Single source of truth for SDK version
142+
- Read by `gradle/versioning.gradle` and injected into BuildConfig
143+
144+
### Required Manifest Placeholders
145+
```gradle
146+
android {
147+
defaultConfig {
148+
manifestPlaceholders = [
149+
auth0Domain: "YOUR_DOMAIN",
150+
auth0Scheme: "https" // or custom scheme
151+
]
152+
}
153+
}
154+
```
155+
156+
### String Resources Pattern
157+
```xml
158+
<string name="com_auth0_client_id">YOUR_CLIENT_ID</string>
159+
<string name="com_auth0_domain">YOUR_DOMAIN</string>
160+
```
161+
162+
## Dependencies
163+
164+
### Core Libraries
165+
- **AndroidX**: Activity, Browser, Biometric, Lifecycle
166+
- **Kotlin Coroutines**: For async operations
167+
- **OkHttp**: HTTP client
168+
- **Gson**: JSON serialization
169+
- **JWT**: Token parsing and validation
170+
171+
### Testing Libraries
172+
- **JUnit 4**: Test framework
173+
- **Robolectric**: Android unit testing
174+
- **Mockito/PowerMock**: Mocking
175+
- **MockWebServer**: HTTP testing
176+
- **Hamcrest**: Assertions
177+
178+
## Security Considerations
179+
180+
1. **PKCE**: Enabled by default for all OAuth flows
181+
2. **DPoP**: Optional enhanced token security
182+
3. **Keystore**: All credentials encrypted using Android Keystore
183+
4. **Biometric**: LocalAuthentication for secure access
184+
5. **Certificate Pinning**: Configurable via OkHttp interceptors
185+
186+
## Documentation
187+
188+
- **README.md**: Getting started and installation
189+
- **EXAMPLES.md**: Detailed usage examples
190+
- **API docs**: Generated via Dokka (KDoc comments)
191+
- **CHANGELOG.md**: Release notes and breaking changes
192+
- **MIGRATION.md**: Upgrade guides between major versions
193+
194+
## Release Process
195+
196+
1. Update `.version` file
197+
2. Update `CHANGELOG.md`
198+
3. Create release branch
199+
4. CI runs full test suite
200+
5. Manual approval for publication
201+
6. Maven Central publication via `gradle/maven-publish.gradle`
202+
203+
## Common Pitfalls
204+
205+
- **Redirect URIs**: Must match exactly between Auth0 dashboard and app configuration
206+
- **Custom Tabs**: Require Chrome or Chrome Custom Tabs provider installed
207+
- **Biometric**: Requires device credential fallback configuration
208+
- **Coroutines**: Must use appropriate dispatcher for Android operations
209+
- **Proguard**: Keep rules defined in `consumer-rules.pro`
210+
211+
## Getting Help
212+
213+
- **Issues**: GitHub Issues for bugs and feature requests
214+
- **Discussions**: GitHub Discussions for questions
215+
- **Auth0 Community**: https://community.auth0.com/
216+
- **Auth0 Support**: For Auth0 account/dashboard issues
217+
218+
## AI Agent Best Practices
219+
220+
When assisting with this codebase:
221+
222+
1. **Preserve patterns**: Follow existing Builder and callback/coroutine patterns
223+
2. **Test coverage**: Always include tests for new functionality
224+
3. **Backward compatibility**: Consider impact on existing users
225+
4. **Documentation**: Update relevant docs when changing public APIs
226+
5. **Security**: Never compromise security features (PKCE, encryption, etc.)
227+
6. **Android compatibility**: Test across Android versions (API 21+)
228+
7. **Error handling**: Provide clear, actionable error messages
229+
230+
## Example Workflows
231+
232+
### Web Authentication
233+
```kotlin
234+
val account = Auth0(clientId, domain)
235+
WebAuthProvider.login(account)
236+
.withScheme("https")
237+
.withScope("openid profile email")
238+
.start(context, object : Callback<Credentials, AuthenticationException> {
239+
override fun onSuccess(result: Credentials) { /* ... */ }
240+
override fun onFailure(error: AuthenticationException) { /* ... */ }
241+
})
242+
```
243+
244+
245+
### Direct API Authentication
246+
```kotlin
247+
val authClient = AuthenticationAPIClient(account)
248+
authClient.login(email, password, "Username-Password-Authentication")
249+
.start(callback)
250+
```
251+
252+
---
253+

0 commit comments

Comments
 (0)