firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.72k stars 3.97k forks source link

[firebase_auth] Support for an auth provider with identifier 'apple.com' is not implemented. #1794

Closed AmitaiMazliah closed 4 years ago

AmitaiMazliah commented 4 years ago

Describe the bug I'm trying to implement login with apple with firebase I'm using https://pub.dev/packages/apple_sign_in To get the apple cred, than I'm passing the creds to firebase but I'm getting an error

I have enabled apple login in the firebase console

To Reproduce Steps to reproduce the behavior: this is my code

import 'dart:async';
import 'package:apple_sign_in/apple_sign_in.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'dart:convert' show utf8;

class UserRepository {

  static final UserRepository _instance =  UserRepository._internal();
  factory UserRepository() => _instance;

  UserRepository._internal({FirebaseAuth firebaseAuth})
      : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance;

  Future<void> signInWithApple() async {
    final AuthorizationResult result = await AppleSignIn.performRequests([
      AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
    ]);
    AuthCredential credential = OAuthProvider(providerId: "apple.com").getCredential(
        idToken: utf8.decode(result.credential.identityToken)
    );
    return _firebaseAuth.signInWithCredential(credential);
  }
}

I'm getting the cred back from apple, than I'm creating firebase AuthCredential successfully. I'm getting an exception on this line _firebaseAuth.signInWithCredential(credential);

This is the exception log:


Credential: Authorization Credential:
 UID: 000999.926e6af69be040daa4fb63d5f62a6053.1958 
 Identity Token: {length = 752, bytes = 0x65794a72 61575169 4f694a42 53555250 ... 79326437 6d724941 } 
 AuthorizationCode: {length = 63, bytes = 0x63366634 38303663 62316234 64343536 ... 78484175 34687867 } 
 User Verification Result: 0 
 User Info: <AKUserInformation: 0x600001bc8370 {
    givenName: Amitai,
    familyName: Mazliah,
    forwardingEmail: (null),
    accountName: (null),
    accountAliases: (null),
    reachableEmails: (null),
    authorizedApplicationsListVersion: (null),
    masterKeyID: (null),
    vettedPrimaryEmail: (null),
    credential =     {
        authorizationCode = "<FlutterStandardTypedData: 0x600002c01040>";
        authorizedScopes =         (
        );
        email = "amitaimazliah@gmail.com";
        fullName =         {
            familyName = Mazliah;
            givenName = Amitai;
            middleName = "<null>";
            namePrefix = "<null>";
            nameSuffix = "<null>";
            nickname = "<null>";
        };
        identityToken = "<FlutterStandardTypedData: 0x600002c00380>";
        realUserStatus = 1;
        state = "<null>";
        user = "000999.926e6af69be040daa4fb63d5f62a6053.1958";
    };
    credentialType = ASAuthorizationAppleIDCredential;
    status = authorized;
}
Support for an auth provider with identifier 'apple.com' is not implemented.
Lost connection to device.

```After the exception the app crashes.

**Expected behavior**
Firebase allow the user to login and create a new user if it doesn't exsists yet.
asm495 commented 4 years ago

Implementing Apple sign in today for the first time and I am experiencing this issue too.

iapicca commented 4 years ago

Hi @AmitaiMazliah given the official firebase docs about signing in with apple I'm not aware if the 3rd party plugin apple_sign_in [github] provides what is required, although, without this being any type of endorsement, it seems to be possible in this article. Without hijacking the issue, this would be an opportunity to provide documentation about achieving this without relying on 3rd party plugins.

https://github.com/FirebaseExtended/flutterfire/pull/1549 https://github.com/FirebaseExtended/flutterfire/issues/1434

y4gamilight commented 4 years ago

Hi @AmitaiMazliah,

I have a same issue and I debugged with XCode, I detected condition for customAuthCredential ([provider length] != 0 && data[@"idToken"] != (id)[NSNull null] && (data[@"accessToken"] != (id)[NSNull null] | data[@"rawNonce"] != (id)[NSNull null])) It means that you need to send argument accessToken or rawNonce to FirebaseAuth can create AuthCredential. About rawNonce, you need sha256 random string, Firebase had topic about that https://firebase.google.com/docs/auth/ios/apple It's worked with me

azhar-rafiq commented 4 years ago

now it is works following https://medium.com/@kevinlivin/it-seems-you-are-using-oauthprovider-from-5462fd0e2a5e

Salakar commented 4 years ago

Hey 👋

Our rework of the Auth, Core & Firestore plugins as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features.

As part of this we introduced a new documentation site which should has a lot of new documentation that should cover this issue (there's a new social auth section on the docs) & others in general. If you spot any issues on the documentation or anything missing then please raise a new GitHub issue, or better yet suggest a change via a Pull Request (there's a 'Edit this page' button at the bottom of every page on the docs).

Additionally, for help migrating to these new plugins I'd recommend checking out the migration guide: https://firebase.flutter.dev/docs/migration