Auth0.Android

Auth0.Android is a client-side library you can use with your Android app to authenticate users and access Auth0 APIs.

Check out the Auth0.Android repository on GitHub.

Requirements

Android API version 21 or newer is required.

Installation

Add the SDK into your project. The library will make requests to Auth0's Authentication and Management APIs.

Add Auth0 to Gradle

In your app's build.gradle dependencies section, add the following:

dependencies {
  // Add the Auth0 Android SDK
  implementation 'com.auth0.android:auth0:2.+'
}

If Android Studio lints the + sign, or if you want to use a fixed version, check for the latest in Maven or JCenter.

Sync Project with Gradle

Remember to synchronize using the Android Studio prompt or run ./gradlew clean build from the command line. For more information about Gradle usage, check their official documentation.

In the android section, target Java 8 byte code for Android and Kotlin plugins respectively.

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  kotlinOptions {
    jvmTarget = '1.8'
  }
}

Permissions

Open your application's AndroidManifest.xml file and add the following permission.

<uses-permission android:name="android.permission.INTERNET" />

Configure for Universal Login

First, go to Dashboard > Applications and click the name of the application you want to edit. In Allowed Callback URLs, make sure your URL follows this format: https://YOUR_DOMAIN/android/{YOUR_APP_PACKAGE_NAME}/callback

Next, replace {YOUR_APP_PACKAGE_NAME} with your actual application's package name. You can find this in your app/build.gradle file as the applicationId value.

Then, in your app/build.gradle file, add the Manifest Placeholders for the Auth0 Domain and the Auth0 Scheme properties, which the library will use to register an intent-filter that captures the callback URI.

If you don't plan to use the Web Authentication feature and not declare the manifest placeholders, you can manually redeclare the activity in your Android app's manifest file to remove it from the merged manifest file. This will prevent Gradle from complaining that the manifest placeholders are missing.

Please read the FAQ for more information.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.auth0.samples"
        minSdkVersion 21
        targetSdkVersion 30
        //...

        //---> Add the next line
        manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "https"]
        //<---
    }
    //...
}

It's a good practice to define reusable resources like @string/com_auth0_domain rather than just hard-coding them.

Initialize Auth0

Create a new Auth0 object using your Auth0 client ID and domain value. Objects will later use this when interacting with Auth0's endpoints.

to configure this snippet with your account

val auth0 = Auth0("YOUR_CLIENT_ID", "YOUR_DOMAIN")

You can also initialize this object using an Android Context, as shown in this usage example.

Next steps

Log users in and out of your application using the WebAuthProvider class.

Reset user password

To initiate a password reset for a user, call resetPassword with the user's email address and the database connection name as parameters.

Password reset requests will fail on network-related errors, but will not fail if the designated email does not exist in the database (for security reasons).

Learn more