小编spo*_*dem的帖子

Flutter Apple 登录 - 空电子邮件

我正在尝试使用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 …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-authentication flutter apple-sign-in

4
推荐指数
2
解决办法
2043
查看次数