Firebaseui-web: How to retrieve provider specific values such as accessToken, providerUserId etc.

Created on 2 Sep 2016  路  4Comments  路  Source: firebase/firebaseui-web

In earlier firebase versions[https://www.firebase.com/docs/web/guide/login/facebook.html] there is a way to retrieve Facebook(or other provider) specific data, such as _facebook.accessToken; facebook.id_, through authdata object.

Even for current firebase version [https://firebase.google.com/docs/auth/web/facebook-login], var token = result.credential.accessToken; can retrieve providers oAuthToken (if not any other information?)

So for Firebae-UI

  • Is this feature available through firebase-ui?
  • Any possible work around (if not available through firebase-ui)?
  • Is their any documentation around. (sorry if it exist, but I am not able to find)?

Example use case to elaborate why it is required:

  1. user login using firebase-ui along with requesting access to scopes ->successful login
  2. auth state changes, retrieve the firebase token+firebase uid+ facebook user token+facebook user ID ->send to external server
  3. validate firebase token->store the firebase uid,facebook user ID on external-server
  4. Later whenever-> retrieve the scope values directly from facebook, by external-server to facebook call.
    (say _user_likes_ is scope in consideration, at Facebook this scope values will keep changing, so one retrieves the updated _user_likes_ list by a periodic GET which requires _Facebook user_id_ along with other parameters to be passed)

All 4 comments

Hi @jalajc,
The signInSuccess callback returns the credential as the second parameter, when a provider like Facebook has been used for sign-in. See the section concerning this: https://github.com/firebase/firebaseui-web#available-callbacks
You can then retrieve the accessToken from this object.
Is that what you're looking for?

@TMSCH not exactly, may be because only one call back is provided currently. that doesn't solve things for me.

Consider another case: My app want to post a status to user's Google plus feed and Facebook feed. Therefore while login using firebaseUI, App also requests the scope/permission to access and write feeds/post. User gives permission. Login is successful. Callback _credential_ is received and stored. However oAuth token is also returned by facebook/googleplus oAuth identity provider.Also user's unique identity in facebook system (may be in google too) is also returned (not the uid of firebase) by oAuth provider. But these parameters are not visible in signinsuccess callback; leaving me clueless if I have to post to user's feed in future how I will do.

While the older version of firebase[https://www.firebase.com/docs/web/guide/login/facebook.html] gave access to some key callback parameters such as facebook.id, I don't see that in firebase.js/firebase-ui docs.

If I understand correctly, you only need the Facebook uid and the credential, is that right? You can access it in the providerData attribute of the User instance. It contains a list of provider's data, with the user's uid of the provider.

Example:

signInSuccess: function(user, credential) {
  var facebookUid;
  for (var providerInfo of user.providerData) {
    if (providerInfo.providerId == 'facebook.com') {
      facebookUid = providerInfo.uid;
    }
  }
}

Does that solve your issue?

@TMSCH (Sorry mate, wasn't possible to reply earlier)
Thanks. :+1: Yups thats what I was looking. With this specific snippet I see what you were inferring to earlier. I also figured out decoding token from accessToken (with all those public key thing ;) ) :

user.getToken().then(function(accessToken) {
              document.getElementById('account-details').textContent = JSON.stringify({
                displayName: displayName,
                email: email,
                emailVerified: emailVerified,
                photoURL: photoURL,
                uid: uid, /*facebook Id*/
                accessToken: accessToken,
                providerData: providerData
              }, null, '  ');
            });

My bad, I didn't understood it first time, may be I was perplexed in the documentation.

@bojeil-google also answered me here. Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deepfriedbrain picture deepfriedbrain  路  5Comments

saul-mtz picture saul-mtz  路  5Comments

mattpalermo picture mattpalermo  路  3Comments

joshkuhar picture joshkuhar  路  5Comments

polo13999 picture polo13999  路  3Comments