Flutter应用程序-使用Apple登录而不向Firebase返回名称,为什么?

vd2z7a6w  于 11个月前  发布在  Flutter
关注(0)|答案(1)|浏览(169)

我有一个Flutter应用程序,使用sign in with Apple package与Firebase,但我无法返回用户名。我如何返回Apple用户名?任何帮助将不胜感激。
这是我目前为止得到的代码。对我遗漏的内容有什么想法吗?

Future<UserCredential> appleSignIn() async {
  if (kIsWeb) {
    final provider = OAuthProvider("apple.com")
      ..addScope('email')
      ..addScope('name');

    // Sign in the user with Firebase.
    return await FirebaseAuth.instance.signInWithPopup(provider);
  }

  final rawNonce = generateNonce();
  final nonce = sha256ofString(rawNonce);

  // Request credential for the currently signed in Apple account.
  final appleCredential = await SignInWithApple.getAppleIDCredential(
    scopes: [
      AppleIDAuthorizationScopes.email,
      AppleIDAuthorizationScopes.fullName,
    ],
    nonce: nonce,
  );

  // Create an `OAuthCredential` from the credential returned by Apple.
  final oauthCredential = OAuthProvider("apple.com").credential(
    idToken: appleCredential.identityToken,
    rawNonce: rawNonce,
  );

  // Sign in the user with Firebase. If the nonce we generated earlier does
  // not match the nonce in `appleCredential.identityToken`, sign in will fail.
  return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
}

Future<User?> signInWithApple(BuildContext context) =>
    signInOrCreateAccount(context, appleSignIn, 'APPLE');

字符串

knsnq2tg

knsnq2tg1#

尝试在使用Apple设置的登录中撤销应用程序的登录访问权限
你可以通过进入设置->你的苹果ID ->登录和安全->登录苹果,选择应用程序,然后点击停止使用苹果ID
如果其他人遇到这个问题,想知道如何使用默认的Firebase auth插件获取name & email,而不是sign_in_with_apple,你需要添加作用域:

final appleProvider = AppleAuthProvider();
appleProvider.addScope("email");
appleProvider.addScope('name');

字符串

相关问题