Search code examples
androidgoogle-smartlockpasswords

Google Smart Lock across multiple apps


I've been trying to get Google's Smart Lock to work between two apps that I have (unfortunately with different keystores), but not having any luck.

It's straightforward to save a password in Smart Lock for one app (APP 1) doing something like:

Credential credential = new Credential.Builder(email)
            .setPassword(password)
            .build();
Auth.CredentialsApi.save(mCredentialsApiClient, credential).setResultCallback(...

However, when I try to make a CredentialRequest in APP 2 it's not able to read the same credentials saved from APP 1. I've tried setting the accountType to the same identifier between them like:

Credential credential = new Credential.Builder(email)
            .setPassword(password)
            .setAccountType(ACCOUNT_TYPE)
            .build();
Auth.CredentialsApi.save(mCredentialsApiClient, credential).setResultCallback(...
...
CredentialRequest request = new CredentialRequest.Builder()
            .setAccountTypes(ACCOUNT_TYPE)
            .build();

Auth.CredentialsApi.request(mCredentialsApiClient, request).setResultCallback(...

But I get an exception stating you can't set both the password and accountType on the same credential (which matches what the documentation says).

Anyone tried something similar between two apps? I should note, I'm unable to tie my credentials from the apps up with my website sign in at the moment, so can't use the Digital Asset Links mechanism.


Solution

  • For security reasons, the digit asset linking is the only way to associate multiple apps with different package names and signing certificates for password retreival with Smart Lock.

    If you can't support credentials from the website yet, then simply exclude the "web" target from the digital asset links file and credentials will only be shared between the apps (but you still have to host the file somewhere and include a link to this file in both app manifests).