Flutterfire: [FIREBASE_AUTH] Apple Sign in with firebase

Created on 23 Feb 2020  路  18Comments  路  Source: FirebaseExtended/flutterfire

Is your feature request related to a problem? Please describe.
Apple do not approve IOS app without sign in with apple option. I use firebase auth for google sign in. But i dont see any option for Apple Sign in. Right now i am using git "https://github.com/zariweyo/flutterfire.git". But this git is getting old and I am unable to use any of your latest updates because that still do not support apple sign in.

Describe the solution you'd like
The best solution should be the same as Google Sign In. If not then whatever is available in the above git. Please merge the same to your latest update.

Additional context
firebase_auth:
git:
url: https://github.com/zariweyo/flutterfire.git
path: packages/firebase_auth/firebase_auth
ref: develop

customer-response ios auth needs-repro documentation

Most helpful comment

Seems to lack of capability to handle linkWithCredential.
Because Sign in with Apple does not permit to use the same credential twice, we need to get new credential if 'ERROR_CREDENTIAL_ALREADY_IN_USE' occured when linkWithCredential, by using error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey].
Otherwise stuck with 'ERROR_MISSING_OR_INVALID_NONCE' error.
However I can't find the way to get error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey].

Ref: https://github.com/firebase/firebase-ios-sdk/issues/4434#issuecomment-564776016

This problem is originaly mentioned #2253

All 18 comments

Go to your Firebase Console, open your Project, choose Authentication, and click on the Sign-in method tab. You need to enable the Apple provider.

Go to your Firebase Console, open your Project, choose Authentication, and click on the Sign-in method tab. You need to enable the Apple provider.

Flutter does however not provide a frontend solution to sign in with Apple credentials.

@dheerajsarwaiya the changes in the repo you mentioned were merged with https://github.com/FirebaseExtended/flutterfire/pull/1526.

Seems to lack of capability to handle linkWithCredential.
Because Sign in with Apple does not permit to use the same credential twice, we need to get new credential if 'ERROR_CREDENTIAL_ALREADY_IN_USE' occured when linkWithCredential, by using error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey].
Otherwise stuck with 'ERROR_MISSING_OR_INVALID_NONCE' error.
However I can't find the way to get error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey].

Ref: https://github.com/firebase/firebase-ios-sdk/issues/4434#issuecomment-564776016

This problem is originaly mentioned #2253

The package readme also needs documentation updates for the iOS section to specifically mention the steps needed to enable Apple as a provider for firebase auth.

@Salakar
I believe there is not only documentation issue but also lack of feature.
The label should be type:missing-feature.

Or should we re-open #2253 and treat https://github.com/FirebaseExtended/flutterfire/issues/2048#issuecomment-611349941 as specific issue other than general 'Apple Sign in with firebase' issue?

@addie9000 it was my understanding that this is already possible using the apple_signin_plugin along with the OAuth provider - https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_auth/firebase_auth/lib/src/auth_provider/oauth_auth_provider.dart

Is this not the case?

Documentation label added for the purpose of documenting an example of integrating the two.

@Salakar
Partially yes.
However linkWithCredential does not work with existing user as mentioned #2253 and my comment.
And more specific issue #2253 is closed and suggested to discuss about the issue here.

@addie9000 ah ok that makes more sense - am I right in assuming then that it's just the information on the error (specifically the FIRAuthErrorUserInfoUpdatedCredentialKey data) that needs exposing to Dart?

We're tracking all these 'error' issues on #1456 - we'll be looking at parsing native error messages & codes and bubbling these up to the Dart layer in a consistent cross-platform format, including associated error information such as this one.

@Salakar
Yes, indeed.
I've just found that issue and thought to link here. Now it's clear that we can discuss about this topic on #1456 if needed. The remaining of this issue for me is only documentation as you said.

Thank you!

@Salakar
Yes, indeed.
I've just found that issue and thought to link here. Now it's clear that we can discuss about this topic on #1456 if needed. The remaining of this issue for me is only documentation as you said.

Thank you!

Great, thanks for helping clarify 馃槄 we'll keep both issues open as they tracking separate things.

@Salakar I think it would be good to address this documentation part sooner rather than later to give users a bit of time before the June 30th deadline to adjust their own code to support an Apple sign in frontend.

FWIW, https://pub.dev/packages/sign_in_with_apple was included in the Flutter Favorite list and I suspect their maintainers would be happy to work with you if any adjustments needed to be made.

We have fixed this issue by our own with the following change: https://github.com/brancedev/flutterfire/commit/66c8aa6ec73d49e6f6e04514edf263ad986ea34a

First we have tried to expose the updated credentials to flutter but the issue was that not all of the internal fields are exposed (e.g. rawNonce) from the internal auth sdk. So we have just added this directly to the linkWithCredential flow and it have worked :)

I have a question on integration with a third party plugin for Android. I have found one that supports android which is the plugin you reference above which is https://pub.dev/packages/sign_in_with_apple. Issue is their solution requires you to use your own server to handle the redirection like this https://github.com/aboutyou/dart_packages/issues/91#issuecomment-642380267 rather than the firebase way which is using a URL like https://PROJECT_ID.firebaseapp.com/__/auth/handler
Is there any docs on how for third party SDKs to interact with the firebase auth handler URL or is that just for the firebase SDK. So if its not possible for third party SDKs to interact with the firebase auth handler then it sounds like the only reasonable solutions per here is one of these solutions:
https://firebase.google.com/docs/auth/android/apple
1) Have a flutter plugin that uses the firebase sdk in Android and communicate that to flutter
2) Use OpenAuth or some other open auth sdk in Android and communicate that to flutter.(I dont see any solutions online which show an example of this on Android.)

Can you confirm?

firebase_auth_oauth does exactly that. It uses the Firebase SDK to perform OAuth authentication on Android devices and the native Apple Sign In flow on iOS 13+ devices. It also works with other OAuth providers.

Usage couldn't be simpler:

// Sign-in by Apple example

FirebaseUser user = await FirebaseAuthOAuth()
          .openSignInFlow("apple.com", ["email"], {"locale": "en"});

Just be aware that at this time, the scope for the user's name is fullName on iOS and name on Android.

firebase_auth_oauth, however, increases the minimum deployment target (granted, just from iOS 8 to iOS 9 but it's still higher than Flutter's default).

Seeing as it's now July (and thus past the June 30 deadline that @xster mentioned), it'd be nice to have an officially sanctioned way to do this with Flutter.

@DavidCorrado note that sign_in_with_apple.dart#L81 states webAuthenticationOptions is only required on Android.

Presumably, if you're only concerned about Apple's App Store requirements, sign_in_with_apple should work for iOS and macOS apps.

Hey 馃憢

Our rework of the firebase_auth plugin as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features. Please could you try the new version and see if this is still an issue on the latest version? If it is then please submit a new up to date GitHub issue. Support for the FIRAuthErrorUserInfoUpdatedCredentialKey was added, and also docs!

See: https://firebase.flutter.dev/docs/auth/error-handling

For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration

@Salakar How does FIRAuthErrorUserInfoUpdatedCredentialKey get supported ? I can't find it anywhere from the doc you provided.

Was this page helpful?
0 / 5 - 0 ratings