我正在尝试使用apple_sign_in包将“Apple登录”添加到我的Flutter iOS应用程序中。代码大部分都能正常工作。我的问题是,对
_firebaseAuth.signInWithCredential(credential)
的调用会创建一个具有空标识符的Firebase帐户(请参见下面的截图)。关于这个问题的一件奇怪的事情是,当用户在注册时选择共享他们的电子邮件地址时,在调用AppleSignIn.performRequests()
后,result.credential.email
包含用户的电子邮件地址。因此,我真的很困惑为什么在创建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;
}