Flutter Apple 登录 - 空电子邮件

spo*_*dem 4 firebase firebase-authentication flutter apple-sign-in

我正在尝试使用apple_sign_in包将“Apple Sign In”添加到我的 Flutter iOS 应用程序中。

该代码主要工作。我的问题是调用_firebaseAuth.signInWithCredential(credential)正在创建一个具有空标识符的 firebase 帐户(请参见下面的屏幕截图)。

关于这一点的一件奇怪的事情是,当用户在注册时选择共享他们的电子邮件地址的选项时,result.credential.email在调用后包含用户的电子邮件地址AppleSignIn.performRequests()。所以我真的很困惑为什么在 Firebase 中创建帐户时没有将用户的电子邮件用作标识符。

  Future<FirebaseUser> signInWithApple() async {
    final AuthorizationResult result = await AppleSignIn.performRequests([
      AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
    ]);

    switch (result.status) {
      case AuthorizationStatus.authorized:
        final AppleIdCredential appleIdCredential = result.credential;

        OAuthProvider oAuthProvider =
        new OAuthProvider(providerId: "apple.com");

        final AuthCredential credential = oAuthProvider.getCredential(
          idToken: String.fromCharCodes(appleIdCredential.identityToken),
          accessToken: String.fromCharCodes(
              appleIdCredential.authorizationCode),
        );

        await _firebaseAuth.signInWithCredential(credential);
        return _firebaseAuth.currentUser();

        break;

      case AuthorizationStatus.error:
        print('Sign in failed: ${result.error.localizedDescription}');
        break;

      case AuthorizationStatus.cancelled:
        print('User cancelled');
        break;
    }

    return null;
  }

Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

小智 5

问题是 iOS 13.6 在 13.5 中我得到了姓名、电子邮件、令牌、id。但在 iOS 13.6 中仅返回用户 ID。我使用sign_in_with_apple依赖项(https://pub.dev/packages/sign_in_with_apple)。


Tan*_*med 5

我相信这是按预期工作的;

Apple 仅在您的应用程序第一次登录设备时返回全名和电子邮件,之后的任何登录都会为这些返回空值。我的猜测是您之前已登录,然后尝试通过新的 Firebase 身份验证用户再次登录,此时名称/电子邮件不再可用。

出于测试目的,再次接收这些信息;转到您的设备设置;设置 > Apple ID、iCloud、iTunes 和 App Store >密码和安全>使用您的 Apple ID 的应用程序,点击您的应用程序,然后点击停止使用 Apple ID。您现在可以再次登录,您将再次收到全名和电子邮件。

这就是 Apple 设计他们的 API 的方式——因此建议您将这些存储在应用程序的其他位置,例如使用 shared_preferences 插件——以便您在需要时始终可以访问它们。