Firebase-ios-sdk: linkAndRetrieveData with Facebook credential fails to retrieve displayName

Created on 15 Aug 2018  路  5Comments  路  Source: firebase/firebase-ios-sdk

[REQUIRED] Step 2: Describe your environment

  • Xcode version: 9.4.1
  • Firebase SDK version: FirebaseCore 5.1.0
  • Firebase Component: Auth
  • Component version: FirebaseAuth 5.0.3

[REQUIRED] Step 3: Describe the problem

If I have an anonymous user and then I login with facebook and use the linkAndRetrieveData, the displayName property of the user is nil.

Steps to reproduce:

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

If I have an anonymous user and then I login with facebook and use the linkAndRetrieveData, the displayName is nil. Checking with the Graph Explorer tool of Facebook and with the retrieved access token from the Facebook SDK I can retrieve my full name.

However, if I use the signInAndRetrieveData from the Auth component, I can retrieve it:

Relevant Code:

Doesn't work
let facebookCredential = FacebookAuthProvider.credential(withAccessToken: facebookAccessToken)
user.linkAndRetrieveData(with: facebookCredential, completion: { result, error in
  if let user = result?.user {
    print(result?.user?.displayName ?? "No display name") // No display name is printed
  }
})
Works
let facebookCredential = FacebookAuthProvider.credential(withAccessToken: facebookAccessToken)
Auth.auth().signInAndRetrieveData(with: facebookCredential, completion: { result, error in
  if let user = result?.user {
    print(result?.user?.displayName ?? "No display name") // Joel M谩rquez is printed
  }                  
})
auth

Most helpful comment

@joelmarquez90 Hi Joel, this is an expected behavior.

  1. When signInAndRetrieveData is called, a new user will be generated and the user info will be updated from user provider info automatically (Facebook in your case).
  2. When linkAndRetrieveData is called, the user provider info will be linked with the current user as providerUserInfo, but will not override user info (displayName in your case). The reason is that a user can link multiple providers and their displayName can be different, so you need to choose and update it yourself.

All 5 comments

could you please see if it return with an error?

I could reproduce this issue with a merge conflict case. In this case, an FUIAuthErrorCodeMergeConflict error would be thrown from firebaseUI. In this case, the call won't succeed and all the user info would be nil (because result is nil).

But it does have a valid credential after a successful login, so it will eventually update all the user information with a cache refresh.

@Yue-Wang-Google no, there's no error on the callback.

In fact, debugging the Firebase iOS SDK code, it seems that at some point is throwing the full name from Facebook.

At this point:

screen shot 2018-08-18 at 17 23 00

The object has this information:

screen shot 2018-08-18 at 17 22 45

And in the last part of the method:

            FIRGetAccountInfoRequest *getAccountInfoRequest =
                [[FIRGetAccountInfoRequest alloc] initWithAccessToken:accessToken
                                                 requestConfiguration:requestConfiguration];
            [FIRAuthBackend getAccountInfo:getAccountInfoRequest
                                  callback:^(FIRGetAccountInfoResponse *_Nullable response,
                                             NSError *_Nullable error) {
              if (error) {
                [self signOutIfTokenIsInvalidWithError:error];
                completeWithError(nil, error);
                return;
              }
              self->_anonymous = NO;
              [self updateWithGetAccountInfoResponse:response];

Inside the [self updateWithGetAccountInfoResponse:response];, the response has the following:

screen shot 2018-08-18 at 17 23 42

It's weird. If you need more information, I'm glad to give it to you.

@joelmarquez90 Hi Joel, this is an expected behavior.

  1. When signInAndRetrieveData is called, a new user will be generated and the user info will be updated from user provider info automatically (Facebook in your case).
  2. When linkAndRetrieveData is called, the user provider info will be linked with the current user as providerUserInfo, but will not override user info (displayName in your case). The reason is that a user can link multiple providers and their displayName can be different, so you need to choose and update it yourself.

Thanks @renkelvin for clearing up that.

Just for anyone there that steps up with this problem, the solution was to check for the providerData first object, and then grabbing the displayName聽on it, which was the Facebook user name.

Was this page helpful?
0 / 5 - 0 ratings