This tutorial demonstrates how to add user login to an Android application using Auth0. We recommend you to Log in to follow this quickstart with examples configured for your account.
I want to integrate with my app15 minutes
I want to explore a sample app2 minutes
Get a sample configured with your account settings or check it out on Github.
Get Your Application Keys
When you signed up for Auth0, a new application was created for you, or you could have created a new one.
You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard.
You need the following information:
- Client ID
We suggest you do not hardcode these values as you may need to change them in the future. Instead, use String Resources, such as
@string/com_auth0_domain, to define the values.
res/values/strings.xml file as follows:
Configure Callback URLs
A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.
The callback URL for your app must be whitelisted in the Allowed Callback URLs field in your Application Settings. If this field is not set, users will be unable to log in to the application and will get an error.
YOUR_APP_PACKAGE_NAME with your application's package name, available as the
applicationId attribute in the
Add the Auth0 Android Dependency
Add the Auth0 Android SDK into your project. The library will make requests to the Auth0's Authentication and Management APIs.
Add Auth0 to Gradle
In your app's
build.gradle dependencies section, add the following:
Sync Project with Gradle Files
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.
Add manifest placeholders required by the SDK. The placeholders are used internally to define an
intent-filter that captures the authentication callback URL.
To add the manifest placeholders, add the next line:
Run Sync Project with Gradle Files inside Android Studio or execute
./gradlew clean assembleDebug from the command line.
Add Authentication with Auth0
Universal Login is the easiest way to set up authentication in your application. We recommend using it for the best experience, best security and the fullest array of features.
onCreate method, create a new instance of the
Auth0 class to hold user credentials and set it to be OIDC conformant.
You can use a constructor that receives an Android Context if you have added the following String resources:
If you prefer to hardcode the resources, use the constructor that receives both strings.
Finally, create a
login method and use the
WebAuthProvider class to authenticate with any connection you enabled on your application in the Auth0 dashboard.
After you call the
WebAuthProvider#start function, the browser launches and shows the Lock widget. Once the user authenticates, the callback URL is called. The callback URL contains the final result of the authentication process.
Capture the Result
Whitelist the callback URL for your app in the Allowed Callback URLs section in Application settings. In that section, enter the following URL:
After authentication, the browser redirects the user to your application with the authentication result. The SDK captures the result and parses it, returning it on the callback instance you defined.
AndroidManifest.xml file should look like this:
There are many options to customize the authentication with the
WebAuthProvider builder. You can read about them in the Auth0 SDK for Android documentation.