Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign in with Apple not passing through fullName #4393

Closed
RobSwish opened this issue Nov 25, 2019 · 52 comments
Closed

Sign in with Apple not passing through fullName #4393

RobSwish opened this issue Nov 25, 2019 · 52 comments

Comments

@RobSwish
Copy link

RobSwish commented Nov 25, 2019

  • Xcode version: Version 11.2.1 (11B53)
  • Firebase SDK version: 6.13.0
  • Firebase Component: Auth - Sign in with Apple

Problem

I have added "Sign in with Apple" to my app. It all works perfectly except it does not pass the name through when authenticating. I am asking for full name and email in my code.

request.requestedScopes = [.fullName, .email]

The Sign in with Apple UI does display a cross next to the name, I don't know if it is supposed to show a tick, I've tried tapping this and changing my name but it does not change to a tick.

I can confirm through debugging that the "displayName" property of the Firebase user is nil after creation.

IMG_0321

Relevant Code:

request.requestedScopes = [.fullName, .email]

@rizafran
Copy link
Contributor

Thanks for reporting, @RobSwish. I'll try to replicate this on my end and I'll let you know with any updates.

@rizafran
Copy link
Contributor

For the Sign in with Apple UI, it might be an intended behavior that the cross icon displays next to the name, and not changing to a tick. You may check out the same UI here.

@rizafran
Copy link
Contributor

Hi @RobSwish, I was able to replicate the issue you encountered, and this is an expected behavior. The fullName is not returned in Apple's ID token so that we can't use it as displayName directly. However, you may opt to get the fullName through "appleIDCredential.fullName" in didCompleteWithAuthorization delegate method, and update user's profile by yourselves.

Additionally, it is mentioned here that Apple only shares the address with apps the first time a user signs in.

@paulb777
Copy link
Member

Going to close this, since there's no obvious actions for us. Feel free to follow-up if you have more questions.

@jlubeck
Copy link

jlubeck commented Dec 14, 2019

The documentation here says that:

Usually, Firebase stores the display name the first time a user signs in with Apple, which you can get with Auth.auth().currentUser.displayName. However, if you previously used Apple to sign a user in to the app without using Firebase, Apple will not provide Firebase with the user's display name.

But this is not the case.

I was able to update my user based on @rizafran 's comment (thanks!) but that is not what the doc says. So either changing the docs or making the code do what the docs say would be nice (this last option would be preferred in my opinion!)

@morganchen12 morganchen12 reopened this Dec 16, 2019
@morganchen12
Copy link
Contributor

@renkelvin based on my understanding we should update the documentation here, not the SDK behavior. Is this correct?

@RobSwish
Copy link
Author

Thanks a lot! You got back to me so quickly I didn't notice, sorry!

I do think that the default behaviour should be for Firebase to save the name if it can as this is what it does for the other sign in methods such as Facebook and Google.

But it's good to know I can get the name through the other way you have mentioned.

@morganchen12
Copy link
Contributor

morganchen12 commented Dec 18, 2019

I talked to @renkelvin about this and he mentioned that the current behavior exists because Sign In with Apple's behavior is inconsistent with the other authentication providers (Sign In with Apple does not always return the user's name).

I don't think Firebase saving the name to the user by default is a good idea since it makes it easier to accidentally link the name to other identifiable information, which is against Apple's license agreement if the user has chosen to anonymize their sign in info.

Unless this proves to be a significant pain point during development, we're likely not going to change the Firebase SDK behavior, though we can add this as an opt-in automatic behavior in FirebaseUI (see firebase/FirebaseUI-iOS#815).

@ghost
Copy link

ghost commented Mar 5, 2020

@morganchen12 How is the fullName differs from the email address in this case?

If the app requested both fullName and Email request.requestedScopes = [.fullName, .email]
and the user provided this information, why does firebase store only email as part of FirebaseUser object ?

Below is the relevant part from the agreement:

If a user has chosen to anonymize their user data as part of Sign In with Apple, You agree not to attempt to link such anonymized data with information that directly identifies the individual and that is obtained outside of Sign In with Apple without first obtaining user consent.

`

@brkeyal
Copy link

brkeyal commented Mar 11, 2020

I've re-created the scenario where an Apple user is new and signs in for my app for the first time, and still, Firebase's user (FIRUser) held a null displayName.
Definitely Apple provided the givenName and familyName on that login (on the appleID Credential), but Firebase just doesn't fetch it. Seems like a bug with Firebase.

@SwapnanilDhol
Copy link

I've re-created the scenario where an Apple user is new and signs in for my app for the first time, and still, Firebase's user (FIRUser) held a null displayName.
Definitely Apple provided the givenName and familyName on that login (on the appleID Credential), but Firebase just doesn't fetch it. Seems like a bug with Firebase.

I have the same problem. I removed my app from the list of apps I use Apple Auth with but while signing in I still don't get back the name of the user.

@morganchen12
Copy link
Contributor

Thanks all, I'll take another look at this issue.

@ParkingPal
Copy link

Hello, do we have an update on this issue? I'm an experiencing it, as well.

@kolbasan
Copy link

kolbasan commented Apr 3, 2020

Hi, I am also having this issue. Is this being worked on?

@ParkingPal
Copy link

I'm not sure, but I was able to find a work around that appears to work. The name is available only on the first time authenticating with Apple. In the authorizationController method that is in the docs, take the variable appleIDCredential that is given, and grab both the first and last name. For me, I had variables that looked something like: firstName = appleIDCredential.fullName?.givenName

Once you get those names saved as variables, be sure you save them to the DB, as you will not be able to access them again. Hope this helps you out.

@Chrichton
Copy link

I am experiencing the same problem.
But: When I run my app in the simulator, I get appleIDCredential.fullName each time, when I sign-in.
But when I am using a real device, I don't get it ever.

Question: What does "The name is available only on the first time authenticating with Apple" mean exactly?
Regards, Heiko

@morganchen12
Copy link
Contributor

morganchen12 commented Apr 6, 2020

Question: What does "The name is available only on the first time authenticating with Apple" mean exactly?

It means you'll get the name from Sign in with Apple whenever Apple feels like giving it to you. Sign in with Apple is hostile to systems that try to save PII by design. If you want to guarantee an alias for your user, prompt them to input a display name.

@JeffersonSchuler
Copy link

I think the docs need to be updated to reflect the current behavior, or the behavior needs to be fixed. This issue has been open for quite awhile.

@Chrichton
Copy link

Chrichton commented Apr 10, 2020

I do now know, what the solution to the problem is.
It is explained brilliantly in Peter Friese's blog:
https://peterfriese.dev/replicating-reminder-swiftui-firebase-part3/

  1. When you authenticate for the first time, you get the name 100%. After that your app is linked to your iCloud account and you do not the name again.
    But you can unlink your app:
    As Peter Friese writes:
    "Unlinking your Apple ID from an app that uses Sign in with Apple
    Once you’ve signed in to your app, you cannot repeat the sign-in flow, which makes testing a bit of a challenge. To get back to the initial state, you need to disconnect your Apple ID from your app. Here is how:Go to https://appleid.apple.com and sign in using your Apple ID
    In the Security section, find Apps & Websites using Apple ID and click on Manage…
    You will see a pop-up dialog that shows you all apps that are connected to your Apple ID
    Managing apps using Apple ID.
    Click on the name of the app you want to disconnect
    The following dialog will tell you when you first started using your Apple ID with this application
    Click on Stop using Apple ID to disconnect this app from your Apple ID"

  2. Now you will get the name again.
    You retrieve it via:

if let fullName = appleIDCredential.fullName {
if let givenName = fullName.givenName, let familyName = fullName.familyName {

and via:

let changeRequest = user.createProfileChangeRequest() // (3)
changeRequest.displayName = displayName
changeRequest.commitChanges {

you tell Firebase to store the name into your profile.
Whenever you sign-in to Firebase, Auth.auth().currentUser will now have your fullname.

For detailed information, please look into Peter Friese's Blog.
Hopefully this helps and thanks to Peter Friese.

Best regards from Heiko

@JeffersonSchuler
Copy link

I would like to point out that the behavior is different for Firebase on the web. Using that framework the display name is provided.

@jamiedaniel
Copy link

I can’t get the above solution to work at all. Peter Friese has a great article, but I cannot get his solution to yield any positive results.

Anyone have a working example as of Swift 5.2?

@Theunodb
Copy link

The values are being returned from Apple, populating it in the displayName would make life much easier:

      String nonce = UtilitiesHelper.randomNonceString();
      AuthorizationCredentialAppleID credential = await SignInWithApple.getAppleIDCredential(
        scopes: [
          AppleIDAuthorizationScopes.email,
          AppleIDAuthorizationScopes.fullName,
        ],
        nonce: crypto.sha256.convert(utf8.encode(nonce)).toString(),
      );

Above returns a credential with the required values from Apple

      final AuthCredential authCredential = OAuthProvider('apple.com').credential(
        idToken: credential.identityToken,
        rawNonce: nonce,
      );

      UserCredential authResult = await FirebaseAuth.instance.signInWithCredential(authCredential);

But it doesn't get added to the authResult values

@mbevin
Copy link

mbevin commented May 8, 2022

Apple is rejecting apps if they don't pre-fill user name fields in-app with the name given by apple during apple authentication, so this really needs to be fixed, as it blocks apps from being successfully submitted to the AppStore.

@sidsarasvati
Copy link

Is there a agreed upon workaround for getting the display name?

@mbevin
Copy link

mbevin commented Jun 11, 2022

Is there a agreed upon workaround for getting the display name?

This is a patch that I used in a fork I made of https://github.com/firebase/flutterfire.git, which saves the given+family name from the credentials provided by Apple to SharedPreferences, which our app then can retrieve later. It was applied to the flutterfire_ui 0.4.0+5 state - https://gist.github.com/mbevin/393597735c67575eccf0858c4c17168d

@rahat14
Copy link

rahat14 commented Aug 20, 2022

Same issue Auth.auth().currentUser.displayName not getting the name after apple sign in via firebase. App has been rejected from ios store .

@peterfriese
Copy link
Contributor

This is being worked on in #10068 (Add Sign in with Apple Display Name API and unit test).

@GregoryConrad
Copy link

@peterfriese Is there any update on #10068? I would use the workaround above; however, I am using Flutter with the Firebase Auth package so that would be a bit of a pain unless I absolutely need to.

@peterfriese
Copy link
Contributor

Let me check with the team, @GregoryConrad !

@andoma93
Copy link

andoma93 commented Oct 9, 2022

Hello, this is absolutely needed because Apple is rejecting apps. Urgency is needed on this issue @peterfriese .
Thanks you!

@coolioxlr
Copy link

Hello, this is absolutely needed because Apple is rejecting apps. Urgency is needed on this issue @peterfriese . Thanks you!

Our app just got rejected as well. :(

@coolioxlr
Copy link

coolioxlr commented Oct 20, 2022

We were able to work around the submission it by not asking for a name
request.requestedScopes = [.email]

@peterfriese
Copy link
Contributor

peterfriese commented Oct 27, 2022

A video explaining how to update the display name is going live tomorrow. In the meantime, check out this code snippet (source: https://bit.ly/SiwA-updateDisplayName):

func updateDisplayName(for user: User, with appleIDCredential: ASAuthorizationAppleIDCredential, force: Bool = false) async {
    if let currentDisplayName = Auth.auth().currentUser?.displayName, !currentDisplayName.isEmpty {
      // current user is non-empty, don't overwrite it
    }
    else {
      let changeRequest = user.createProfileChangeRequest()
      changeRequest.displayName = appleIDCredential.displayName()
      do {
        try await changeRequest.commitChanges()
        self.displayName = Auth.auth().currentUser?.displayName ?? ""
      }
      catch {
        print("Unable to update the user's displayname: \(error.localizedDescription)")
        errorMessage = error.localizedDescription
      }
    }
  }

Also, we are working on updating the display name when the user first signs in with SiwA. As this requires some backend changes, it might take a couple more weeks to land. I will keep this bug updates as we make progress.

@GregoryConrad
Copy link

Also, we are working on updating the display name when the user first signs in with SiwA.

Just to clarify: are you saying that in a couple weeks, apps will have the displayName variable set in the user object itself when the user first logs in with SIWA?

@peterfriese
Copy link
Contributor

peterfriese commented Oct 28, 2022

See PR #10068 which contains the front-end work for this.

@andoma93
Copy link

andoma93 commented Nov 2, 2022

We are using FirebaseAuthUI, so this workaround should be implemented by Google too. @peterfriese

@peterfriese
Copy link
Contributor

Hi everyone,

I am happy to report that we've merged the code for setting the user's displayname to the SiwA full name when authenticating with Apple (#10068).

You can set the displayname to the SiwA fullname like this:

// Initialize a Firebase credential, including the user's full name.
      let credential = OAuthProvider.appleCredential(withIDToken: idTokenString,
                                                        rawNonce: nonce,
                                                        fullName: appleIDCredential.fullName)

Docs and QuickStart have been updated:

@paulb777
Copy link
Member

Thanks @peterfriese and team! 🎆

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests