我正在尝试使用 expo-apple-authentication 实现 React Native Firebase Auth。我已将 Apple 添加为 Firebase 身份验证控制台上的提供者,但由于 expo-apple-authentication 返回身份令牌和授权代码,而不是根据文档返回身份令牌和随机数,因此我无法使用身份验证反应本机 Firebase。我尝试手动生成一个随机数来与身份令牌一起使用,但得到 [auth/invalid-credential] 提供的身份验证凭据格式错误或已过期。
有人知道该怎么做吗?
我当前的代码
const signInWApple = async () => {
try {
const credential = await AppleAuthentication.signInAsync({
requestedScopes: [
AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
AppleAuthentication.AppleAuthenticationScope.EMAIL,
],
});
// Ensure Apple returned a user identityToken
if (!credential.identityToken) {
throw new Error("Apple Sign-In failed - no identify token returned");
}
// Create a Firebase credential from the response
const { identityToken } = credential;
const nonce = generateRandomNonce();
const appleCredential = auth.AppleAuthProvider.credential(
identityToken,
nonce
);
// Sign the user in with the credential
await auth().signInWithCredential(appleCredential);
}
事实证明,您可以使用授权码作为随机数。但是,当您在 Firebase 控制台上激活 Apple 登录时,您必须在服务 ID 字段中包含您的捆绑 ID(类似于 com.yourapp.appOne),否则 Firebase 将不会接受身份验证。您可以在 Apple 开发者帐户的“证书、标识符和配置文件”下找到您的捆绑包 ID。