baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

When i use Apple authentication on iOS, does not get user full name #191

Open santosbj opened 2 years ago

santosbj commented 2 years ago

I try this cfaSignInApple().pipe(first()).subscribe( (user: any) => { user.displayName = this.preferences.userName; user.email = this.preferences.email; }, (err) => { ....

But userName is always empty.

This is a issue or i'm doing something wrong?..

This is my config: CapacitorFirebaseAuth: { providers: [ "google.com", "facebook.com", "apple.com", "phone" ], languageCode: "en", nativeAuth: false, permissions: { "google": [ "profile", "email" ], "facebook": [ "profile", "email" ], "apple": [ "email", "name", "fullName" ] }

Thanks!

baumblatt commented 2 years ago

Hello Santos,

Unless I'm wrong, those are restrictions of Apple Authentication Provider for privacy propose.

In fact, the user could also change his name during the first authentication and choose to share or not his real email.

Please, take a look at documentation for others restrictions:

Unlike other providers supported by Firebase Auth, Apple does not provide a photo URL. Also, when the user chooses not to share their email with the app, Apple provisions a unique email address for that user (of the form xyz@privaterelay.appleid.com), which it shares with your app. If you configured the private email relay service, Apple forwards emails sent to the anonymized address to the user's real email address.

Apple only shares user information such as the display name with apps the first time a user signs in. 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. Source.

Anyway, the plugin code is almost exactly as the sample in the docs above, but please, if you find something that we could changed let us know.

Best regards.

TylerAHolden commented 2 years ago

Hi @baumblatt I'm having a similar issue and unfortunately, Apple is blocking my app from app store approval because "I should not be prompting users for their name" - but I have to since this plugin is not returning the display name on the firebase user object...

It looks like part of the issue is because the firebase SDK does not store the name apple provides as the display name: See (https://github.com/firebase/firebase-ios-sdk/issues/4393) ["The fullName is not returned in Apple's ID token". ] I think the reason firebase has not addressed the issue is to prevent the assumption that users' name should be automatically saved for privacy reasons.

I tinkered with this source code and found that appleIDCredential.fullName DOES return the name, however, it appears this particular key/value is never passed back to firebase or the callback function, therefore it is impossible to get in javascript. Is that correct? Apologies - I am not skilled with swift - Can we send appleIDCredential.fullName in the callback function along with the firebase.user so that we can optionally save the users name? I think this is important especially since Apple will only provide this once and apparently they require new apps to utilize the given name without prompting users to manually enter their name.

TylerAHolden commented 2 years ago

I'll test https://github.com/baumblatt/capacitor-firebase-auth/pull/194 more tomorrow but i believe this would resolve the issue. @baumblatt let me know your thoughts - I'm happy to try playing around more with the swift code I just don't know exactly what I'm doing! This is kind of a "gotcha" not documented very well from the firebase iOS SDK so idk how we should handle this to make it clear that apple provides the name once and why it is NOT saved as the displayName in the firebase auth user object.

moblizeitllc commented 2 years ago

i am having the same issue. apple is not approving my app as i am asking for first and last name because plugin does not return it. plz advise how to fix it.

DanielPipa2 commented 2 years ago

TylerAHolden

Your solution doesn't work for me. Did you manage to solve it?

TylerAHolden commented 2 years ago

TylerAHolden

Your solution doesn't work for me. Did you manage to solve it?

Yea my fix should work. It's currently working for me. My implementation returns an additional name property on the initial login user object.

Just remember that apple only returns the full name on the VERY first sign in. After that, you'll never get it again. If you want to completely reset the apple auth (to get the name again), you need to go into your Apple ID settings and remove your app - this will probably point you in the right direction to do so https://stackoverflow.com/questions/58018184/how-to-revoke-sign-in-with-apple-credentials-for-a-specific-app

DanielPipa2 commented 2 years ago

Thank you very much! Your solution helped me! I want to add that I missed this: const { cfaSignInApple } = await import( "capacitor-firebase-auth/alternative" );