Integrate 1Password into your Android apps

Account sign-up and sign-in is a critical piece of your app, but it’s also the part that is most likely to create friction for new users. It might be necessary for your app to collect information such as an email address and password, but let’s face it, those details are rather tedious to type out.

Here’s something that happens far more often than it should. I’m out with a friend and they’ve just told me about this fantastic new app. I get fired up and download it to my phone, only to be confronted with a wall of text fields. I need to register for a new account before I can continue, and that seems like a lot of work. So I tell myself that I’ll do it when I get home and of course, I forget all about it. By the time I look at the app again, I’ve lost that initial excitement and more often than not, I just delete the app.

If I do give the app another chance, I still need to go through the hassle of creating a new account. Of course, I have 1Password to help me here, but I still need to switch between apps, copying and pasting the values as I go. Wouldn’t it be so much better if the app could just ask 1Password to create my credentials and then sign me in?

I’m very happy to say that this is no longer just wishful thinking! We’ve been working closely with Google and other leading password managers on a protocol for Android called OpenYOLO. This new protocol provides the kind of seamless integration that would have saved me so much of the frustration above. The best part is that implementing the protocol is simple, and you can get started on integrating it into your Android app today!

Getting started with OpenYOLO


You Only Login Once (YOLO) is Google’s internal code name for their Smart Lock for Passwords API on Android. OpenYOLO is its open-source successor that enables client apps to communicate directly with supported providers like 1Password. Using OpenYOLO, your app can ask 1Password to create, save, retrieve, or delete its user credentials.

It’s almost effortless to integrate 1Password with your app using OpenYOLO! Let me show you just how easy it is to get started…

Import the library

Add this line to your app’s build.gradle file to import the OpenYOLO API:

dependencies {
    compile 'org.openyolo:openyolo-api:0.3.1'
}

Get the client

You’ll need an instance of CredentialClient in order to interact with OpenYOLO. It provides convenience methods for sending requests and retrieving responses.

mCredentialClient = CredentialClient.getInstance(this);

Prepare the request

For each operation, your app needs to prepare a request and retrieve an Intent for handling it. You can then hand off the request to OpenYOLO with startActivityForResult(). OpenYOLO will take the request and determine if there are any credential providers like 1Password available to handle it. If multiple providers are available, the user will be prompted to select which one to use to complete the request.

Handle the response

Once the chosen provider has completed the request, a response will be returned to your app in onActivityResult(). You can use CredentialClient to pull the relevant information from the response.

Working with 1Password to simplify users’ experiences

Signing up new users

To avoid another story like mine above, you can assist users with new account registration in your app. Before prompting me to manually enter my email address and choose a unique password, your app can make a request to have those credentials generated.

HintRetrieveRequest request = HintRetrieveRequest.fromAuthMethods(AuthenticationMethods.EMAIL);

Intent hintIntent = mCredentialClient.getHintRetrieveIntent(request);

startActivityForResult(hintIntent, HINT_REQUEST_CODE);

In my case, 1Password will prompt me to confirm that I want to create new credentials and OpenYOLO will return details to your app’s onActivityResult().

if (requestCode == HINT_REQUEST_CODE) {
    HintRetrieveResult result = mCredentialClient.getHintRetrieveResult(data);

    if (result.isSuccessful()) {
        Hint hint = mCredentialClient.getHintRetrieveResult(data).getHint();

        signUpUser(hint.getIdentifier(), hint.getGeneratedPassword());
    }
}

Saving user credentials

My account details are all filled in, and I’m ready to start exploring the app, but of course I want to make sure those new account details are stored in 1Password. This will come in handy the next time I need to sign in to your app. You can help here too with a simple save request to OpenYOLO.

Credential credential = new Credential.Builder(mEmail, AuthenticationMethods.EMAIL,
AuthenticationDomain.getSelfAuthDomain(this))
.setPassword(mPassword)
.build();

Intent saveIntent = mCredentialClient.getSaveIntent(CredentialSaveRequest.fromCredential(credential));

startActivityForResult(saveIntent, SAVE_REQUEST_CODE);

Now I am ready to go! Only a couple of seconds after downloading your app, I am all signed up for an account and more importantly, I can begin using it!

Signing in with existing credentials

Okay, now the fun part! My brand new and shiny Pixel 2 XL arrives and I download all of my favourite apps to it. I still need to sign in to my apps, but you’ve gone and saved me all the hassle by once again using OpenYOLO.

CredentialRetrieveRequest request = CredentialRetrieveRequest.fromAuthMethods(AuthenticationMethods.EMAIL);

Intent retrieveIntent = mCredentialClient.getCredentialRetrieveIntent(request);

startActivityForResult(retrieveIntent, RETRIEVE_REQUEST_CODE);

In response to this request, 1Password will prompt me to select my sign-in credentials and OpenYOLO will return them to your app in onActivityResult():

if (requestCode == RETRIEVE_REQUEST_CODE) {
    CredentialRetrieveResult result = mCredentialClient.getCredentialRetrieveResult(data);

    if (result.isSuccessful()) {
        Credential credential = mCredentialClient.getCredentialRetrieveResult(data).getCredential();

        signInUser(credential.getIdentifier(), credential.getPassword());
    }
}

Less noise, more fun!

That’s it! With a few changes to your code, your app now integrates with 1Password using OpenYOLO. This decreases noise from your app and more importantly saves your users time and effort so that they can get to the really important part – using your app.

If a solution like this is in place the next time my buddy gets me to try out your app, I would be able to create an account with a few taps, and they would have the opportunity to show me why they love the app!

DroidCon London 2017

At DroidCon London today, Google announced that OpenYOLO is now ready for developers like yourself to leverage its powers and bring it into the hands of users. If you are also attending the conference, send a wave at my colleague, Michael Verde! He will be available for a hands-on session to help integrate OpenYOLO into your apps.

Reach out to us

For further details on integrating OpenYOLO into your Android app, take a look through the open-source project available on Github. The repository also includes a handful of sample apps to help with development. If you’re curious about the protocol itself, you can read all about it in the OpenYOLO for Android specification.

If you have any questions, feedback or want to let us know that your Android app supports integration with 1Password through OpenYOLO, please reach out to us at support+android@agilebits.com. We look forward to hearing from you!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *