Loading...
Loading...
Use when adding authentication to Android applications (Kotlin/Java) with Web Auth, biometric-protected credentials, and MFA - integrates com.auth0.android:auth0 SDK for native Android apps
npx skill4agent add auth0/agent-skills auth0-androidcom.auth0.android:auth0Agent instruction: Before providing SDK setup instructions, fetch the latest release version by running:gh api repos/auth0/Auth0.Android/releases/latest --jq '.tag_name'Use the returned version in alldependency lines instead of any hardcoded version below. If the command fails, fall back to checking https://github.com/auth0/Auth0.Android/releases.implementation
build.gradleimplementation 'com.auth0.android:auth0:{LATEST_VERSION}'Agent instruction: Check whether the user prompt already includes both Auth0 Client ID and Domain.
- If both are provided, proceed directly to Manual Setup in Setup Guide using those values.
- If either is missing, you MUST ask the user BEFORE writing any code or files:
- Question: "How would you like to configure Auth0 for this project?"
- Options: "Automatic setup (Recommended) — Auth0 CLI creates the app and writes credentials to strings.xml" / "Manual setup — I'll provide my Client ID and Domain"
Then follow Setup Guide for the chosen path. Do NOT proceed to step 3 until Auth0 credentials are confirmed.Note: For native Android apps, Domain and Client ID are public configuration (not secrets). No client secret is used. Write values directly towithout displaying them in conversation output.strings.xml
import com.auth0.android.Auth0
val account = Auth0.getInstance(context)Agent instruction: Before adding new UI elements, search the project for existing click handlers for login, logout, sign-in, or sign-out buttons (e.g.,,loginButton,signInButton,logoutButton, orsignOutButtonwith auth-related naming). If existing handlers are found, hook the Auth0 code into them without modifying the existing UI. Only create new buttons if no existing handlers are found.setOnClickListener
import com.auth0.android.Auth0
import com.auth0.android.authentication.AuthenticationAPIClient
import com.auth0.android.authentication.storage.SecureCredentialsManager
import com.auth0.android.authentication.storage.SharedPreferencesStorage
import com.auth0.android.callback.Callback
import com.auth0.android.authentication.AuthenticationException
import com.auth0.android.provider.WebAuthProvider
import com.auth0.android.result.Credentials
val account = Auth0.getInstance(context)
val authentication = AuthenticationAPIClient(account)
val storage = SharedPreferencesStorage(context)
val credentialsManager = SecureCredentialsManager(context, authentication, storage)
WebAuthProvider.login(account)
.withScheme(getString(R.string.com_auth0_scheme))
.withScope("openid profile email offline_access")
.start(this, object : Callback<Credentials, AuthenticationException> {
override fun onSuccess(result: Credentials) {
// User authenticated
val idToken = result.idToken
val accessToken = result.accessToken
// Store credentials securely
credentialsManager.saveCredentials(result)
}
override fun onFailure(error: AuthenticationException) {
// Handle authentication failure
Log.e("Auth0", "Authentication failed", error)
}
})WebAuthProvider.logout(account)
.withScheme(getString(R.string.com_auth0_scheme))
.start(this, object : Callback<Void?, AuthenticationException> {
override fun onSuccess(result: Void) {
// User logged out
}
override fun onFailure(error: AuthenticationException) {
Log.e("Auth0", "Logout failed", error)
}
})Agent instruction: After completing the integration, build the project to verify it compiles successfully:bash./gradlew assembleDebugIf the build fails, analyze the error output and fix the issues. Common integration build failures include:
- Unresolved reference: Missing import statements — add the required
importsimport com.auth0.android.*- Cannot resolve symbol
:R.string.com_auth0_schemenot updated — verifystrings.xml,com_auth0_scheme, andcom_auth0_client_identries existcom_auth0_domain- Incompatible types in callback: Callback type parameters don't match — ensure
for login andCallback<Credentials, AuthenticationException>for logoutCallback<Void?, AuthenticationException>- Unresolved
: Missing dependency — addlifecycleScopeor move code out of coroutine scopeimplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.+'- minSdk too low: SDK requires API 21+ — update
to at least 21minSdkVersion- Java version mismatch: SDK requires Java 8 — add
withcompileOptionsJavaVersion.VERSION_1_8Re-run the build after each fix. Track the number of build-fix iterations.Failcheck: If the build still fails after 5–6 fix attempts, stop and ask the user:
- Question: "The build is still failing after several fix attempts. How would you like to proceed?"
- Options: "Let the agent continue fixing iteratively" / "I'll fix it manually — show me the errors" / "Skip build verification and proceed"
Repeat this check after every 5–6 iterations if errors persist. Do not leave the project in a non-compiling state without the user's explicit consent.
{SCHEME}://{YOUR_AUTH0_DOMAIN}/android/{YOUR_APP_PACKAGE_NAME}/callback| Mistake | Fix |
|---|---|
| App type not set to Native in Auth0 Dashboard | Create a Native application type in your Auth0 tenant. The Android SDK requires Native app configuration, not Machine-to-Machine or other types. |
| Missing callback URL in Allowed Callback URLs | Add |
Missing | Add the INTERNET permission to |
| Custom scheme in lowercase | Android requires scheme names to be lowercase. Use |
Forgetting | Always call |
| Storing tokens in SharedPreferences without encryption | Use |
| Missing manifest placeholders | Add |
| Class | Purpose |
|---|---|
| Entry point for SDK, holds app credentials |
| OAuth 2.0 login/logout via browser |
| Direct API calls (database login, passwordless, MFA) |
| Secure storage and retrieval of credentials |
| User tokens and expiration |