7

Store Facebook Credential in Google Smart Lock Password

I was able to store basic username/password credentials in Smart Lock Password. There is plenty of documentation and examples for Google credentials:

GoogleSignInAccount gsa = signInResult.getSignInAccount();
Credential credential = new Credential.Builder(gsa.getEmail())
        .setAccountType(IdentityProviders.GOOGLE)
        .setName(gsa.getDisplayName())
        .setProfilePictureUri(gsa.getPhotoUrl())
        .build();

But so far, I was unable to store a Facebook credential. It should be something similar. But what exactly? Or is it something completely different or not supported?

Credential credential = new Credential.Builder(<what goes here?!>)
        .setAccountType(IdentityProviders.FACEBOOK)
        .setName(<and here?>)
        .setProfilePictureUri(<is this necessary?>)
        .build();
Rui
  • 936
  • 10
  • 21
  • 4
    Answer by a Googler https://github.com/googlesamples/android-credentials/issues/6#issuecomment-168844689 – Pauland Jan 05 '16 at 09:22

1 Answers1

0

I was able to get what I believe to be a working version of Smart Lock saving Facebook login credentials.

My app uses the FB API to login. From there I send a token to my server which in turn sends back the users email and username. I store that information like so:

    Credential credential = new Credential.Builder(user.getEmail())
       .setAccountType(IdentityProviders.FACEBOOK)
       .setName(user.getName())
       .build();

I'm not completely familiar with the Facebook API, but I think you could get the email and username from the Facebook SDK.

After using this to save the users FB credentials I am able to view them on passwords.google.com. The password shows as "With Facebook".

Elforama
  • 512
  • 1
  • 4
  • 16
  • 3
    When you launch your app (but you're not signed in), you request credentials. Ok, When you find credential for facebook, how can you "auto" connect with the facebook sdk ? With Google Sign in you can use Auth.GoogleSignInApi.silentSignIn(). – Pauland Dec 30 '15 at 17:15
  • There is no background sign-in that I perform. The loader for Facebook shows as I sign the user in. If you want to avoid any visual indication that they are being signed in to perform a silentSignIn, then I'm in the same boat as you unfortunately. – Elforama Dec 30 '15 at 20:37
  • @Elforama With facebook you basically have to call `registerCallback()` which will provide you with the token in `onSuccess()` this show a loading symbol on the screen but works as a sort of silentSignIn() – pratham kesarkar Feb 26 '19 at 08:21