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

[firebase_auth]: Apple signInWithCredential throws invalid-credential when used with error.credential #12944

Closed
1 task done
eli1stark opened this issue Jun 11, 2024 · 4 comments · Fixed by #12957
Closed
1 task done
Assignees
Labels
Needs Attention This issue needs maintainer attention. platform: ios Issues / PRs which are specifically for iOS. plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@eli1stark
Copy link

eli1stark commented Jun 11, 2024

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Auth

Which platforms are affected?

iOS

Description

firebase_auth: 4.20.0

When converting an anonymous user to a registered account, linkWithProvider may throw an error if the account is already linked to another user. However, we can recover from the error by signing in to the account using the credential from FirebaseAuthException and calling the signInWithCredential function. But for some reason, it throws an error: "[firebase_auth/invalid-credential] The supplied auth credential is malformed, has expired, or is not currently supported." It also prints, "Support for an auth provider with identifier 'apple.com' is not implemented," even though Apple Auth is enabled. The process works fine when used with signInWithProvider. So it seems there is something wrong with the credential passed by the error.

Reproducing the issue

  /// Prerequisites:
  ///
  /// 1. Make sure that your Apple account is already linked to another user.
  /// 2. Make sure you are unauthenticated.
  ///
  /// Issues:
  ///
  /// 1. The token is negative in AuthCredential: `-7025765327691696085`.
  /// 2. [invalid-credential] is thrown when trying to signInWithCredential.
  /// 3. The following text is printed: "Support for an auth provider with
  ///    identifier 'apple.com' is not implemented." Even though Apple auth
  ///    works fine when used with a credential outside of the error.
  ///
  /// How it should work:
  ///
  /// 1. `signInWithCredential` should authenticate successfully.
  Future<void> signInAsGuestAndConvertToRegisteredUser() async {
    await FirebaseAuth.instance.signInAnonymously();

    final provider = AppleAuthProvider();
    final user = FirebaseAuth.instance.currentUser;

    if (user != null && user.isAnonymous) {
      try {
        await user.linkWithProvider(provider);
      } on FirebaseAuthException catch (error) {
        final credential = error.credential;

        print(credential);

        if (credential != null) {
          await FirebaseAuth.instance.signInWithCredential(credential);
        }
      } catch (_) {}
    }
  }

Firebase Core version

2.32.0

Flutter Version

3.22.0

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

Maybe related to #12931 and #11841.


The issue is reproducible on the latest versions:

firebase_core: 3.1.0
firebase_auth: 5.1.0


The issue is reproducible on the following versions:

firebase_core: 2.32.0
firebase_auth: 4.20.0


The issue is NOT reproducible on the following versions:

firebase_core: 2.31.0
firebase_auth: 4.19.5


There is interesting error when using the following versions:

firebase_core: 2.32.0
firebase_auth: 4.19.5

Click to see the error
[log] type 'List<Object?>' is not a subtype of type 'PigeonUserDetails?' in type cast
      #0      PigeonUserCredential.decode (package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart:432:23)
      #1      _FirebaseAuthHostApiCodec.readValueOfType (package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart:830:37)
      #2      StandardMessageCodec.readValue (package:flutter/src/services/message_codecs.dart:477:12)
      #3      StandardMessageCodec.readValueOfType (package:flutter/src/services/message_codecs.dart:522:23)
      #4      _FirebaseAuthHostApiCodec.readValueOfType (package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart:840:22)
      #5      StandardMessageCodec.readValue (package:flutter/src/services/message_codecs.dart:477:12)
      #6      StandardMessageCodec.decodeMessage (package:flutter/src/services/message_codecs.dart:341:28)
      #7      BasicMessageChannel.send (package:flutter/src/services/platform_channel.dart:218:18)
      <asynchronous suspension>
      #8      FirebaseAuthHostApi.signInWithCredential (package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart:1094:9)
      <asynchronous suspension>
      #9      MethodChannelFirebaseAuth.signInWithCredential (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:306:22)
      <asynchronous suspension>
      #10     FirebaseAuth.signInWithCredential (package:firebase_auth/src/firebase_auth.dart:543:9)
      <asynchronous suspension>
@eli1stark eli1stark added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Jun 11, 2024
@MirceaX2Mobile
Copy link

Yes I think its related to this #12944
@russellwheatley

@Lyokone Lyokone added plugin: auth platform: ios Issues / PRs which are specifically for iOS. labels Jun 13, 2024
@russellwheatley russellwheatley self-assigned this Jun 13, 2024
@russellwheatley russellwheatley removed the Needs Attention This issue needs maintainer attention. label Jun 13, 2024
@russellwheatley
Copy link
Member

Hey @eli1stark - fairly sure this is the same issue as @MirceaX2Mobile. Might be worth trying this branch locally in your project and seeing if it fixes the issue: https://github.com/firebase/flutterfire/tree/auth-12931

Just update your pubspec.yaml with this for firebase_auth:

firebase_auth:
    git:
      url: https://github.com/firebase/flutterfire.git
      path: packages/firebase_auth/firebase_auth
      ref: auth-12931

Let me know how it goes 🙏

@russellwheatley russellwheatley added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 13, 2024
@eli1stark
Copy link
Author

@russellwheatley Thank you for your quick response and fix! I can confirm that it's reproduced on firebase_auth: 5.1.0 but not on the branch you provided.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jun 13, 2024
@russellwheatley
Copy link
Member

russellwheatley commented Jun 13, 2024

@eli1stark - Thanks for confirmation! Also, for producing quality issues/reproductions 👍

@TarekkMA TarekkMA added the resolution: fixed A fix has been merged or is pending merge from a PR. label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention This issue needs maintainer attention. platform: ios Issues / PRs which are specifically for iOS. plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
6 participants