Auth0.Android
libraries

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.+'
}

Was this helpful?

/

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'
  }
}

Was this helpful?

/

Permissions

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

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

Was this helpful?

/

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.

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"]
        //<---
    }
    //...
}

Was this helpful?

/

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.

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

Was this helpful?

/

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