TL;DR: Get a sample Android app with Smart Lock configured and ready to use from this Github repository.

Members of our team participated in the last Google I/O to learn about the latest trends. There were a lot of cool new things announced, but these two particularly caught our eyes: Android Fingerprint Support & Smart Lock for Passwords. In this blog post, we’ll focus on the latter.

Smart Lock for Passwords is a service that makes handling your user’s credentials a pain-free process. It also allow friction-free log-in and sign-up for your web & Android apps. In other words, the idea is that you never have to remember your passwords again :). Have you heard about 1Password or LastPass? Well, imagine that, but from Google.

If you’re writing a WebApp, password management can be handled by Chrome itself. However, for Android apps. you need to do some extra work to add it. After playing around with the samples, we decided that it would be great to integrate it with our Lock for Android to make it even easier to authenticate your users and keep their credentials safe. With that in mind, we created a new library Lock-SmartLock. In this blog post, we’ll learn how to use it!

Before we start

First, you need to make sure you have updated Google Play services in your Android SDK installation. (You can update it using Android SDK Manager)

Then, follow this guide to configure your Google Developers Console project and associate it with your Android application so it can use SmartLock API.

In order to use Lock-SmartLock, you’ll need to create an Auth0 application. You can create one from the Auth0 dashboard

Let’s add Lock & SmartLock

Configuring Lock-Smartlock

First, add Lock-SmartLock to your build.gradle file.

compile ‘’

Then, in your res/values folder, create a resource file named auth0.xml that will include your Auth0 credentials:

<?xml version="1.0" encoding="utf-8"?>
    <string name="auth0_client_id">{YOUR_CLIENT_ID}</string>
    <string name="auth0_domain_name">{YOUR_DOMAIN}</string>
    <string name="auth0_scheme">a0{YOUR_CLIENT_ID_LOWERCASE}</string>

In order to authenticate the user, Lock needs access to the Internet. Let’s request that permission in your AndroidManifest.xml:

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

Implementing Lock-Smartlock

Now it’s time to register Lock for Android and Google Play services for your application in your AndroidManifest.xml:

  <!--Auth0 Lock-->
          <action android:name="android.intent.action.VIEW"/>
          <category android:name="android.intent.category.DEFAULT"/>
          <category android:name="android.intent.category.BROWSABLE"/>
          <data android:scheme="@string/auth0_scheme" android:host="@string/auth0_domain_name"/>
  <meta-data android:name="com.auth0.lock.client-id" android:value="@string/auth0_client_id"/>
  <meta-data android:name="com.auth0.lock.domain-url" android:value="@string/auth0_domain_name"/>
  <!--Auth0 Lock End-->

  <meta-data android:name="" android:value="@integer/google_play_services_version" />

Then, we need to create a custom class that extends from and implements LockProvider. In this class, we’ll create an instance of SmartLock and store it so that we can use it from any Activity.

public class MyApplication extends Application implements LockProvider {

    private Lock lock;

    public void onCreate() {
        lock = new SmartLock.Builder(this)

    public Lock getLock() {
        return lock;


Remember to register this class as your application class in the AndroidManfifest.xml, too.

Then, in the Activity that will trigger authentication, override the following lifecycle callbacks that will allow Lock to interact with Smart Lock:

protected void onStart() {

protected void onStop() {

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    SmartLock.getSmartLock(this).onActivityResult(this, requestCode, resultCode, data);

The layout of the Activity is up to you; we only need a way to trigger the authentication (either a button or automatically from code).

Then, we need to create a BroadcastReceiver to handle the events broadcasted by Lock when the user authenticates:

protected void onCreate(Bundle savedInstanceState) {
    //... Setup your Activity
    broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.registerReceiver(authenticationReceiver, new IntentFilter(Lock.AUTHENTICATION_ACTION));

protected void onDestroy() {
    //... Clean up your Activity

private BroadcastReceiver authenticationReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        UserProfile profile = intent.getParcelableExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER);
        Token token = intent.getParcelableExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER);

Finally, in order to authenticate the user, you just call the following method method inside your Activity


Connect your device, and run the app. You’ll see something like this:


That’s it all, you have successfully integrated Auth0 and SmartLock!

Congrats ;)