反应原生androidfirebase登录与苹果[错误:提供的身份验证凭据格式错误,已过期或当前不受支持。]
我正在使用 Apple 实现登录。我可以成功看到Apple登录页面。我输入正确的凭据。它应该能够根据 Apple 的返回值登录/注册 Firebase。
但是我收到了这个错误Error: The supplied auth credential is malformed, has expired or is not currently supported。Firebase 方面一定有问题吗?onPressAppleLogin逻辑上可以参考下面的函数。非常感谢!
我做了什么:
在 Firebase 中
- 已启用Apple 登录提供程序的身份验证
- 我的服务 ID 是co.myexampleapp.signinwithapple
- 我的授权回调是https://my-example-app.firebaseapp.com/__/auth/handler
在 developer.apple.com 中
- 我创建了一个服务 ID co.myexampleapp.signinwithapple并启用了该服务
Sign In with Apple - 我加my-example-app.firebaseapp.com为域和https://my-example-app.firebaseapp.com/__/auth/handler在
Return URLs
我的 React Native 源代码
import { appleAuthAndroid } from '@invertase/react-native-apple-authentication';
import firebase from 'react-native-firebase'
getRandomString = (length: any) => {
let randomChars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let result = ''
for (let i = 0; i < length; i++) {
result += randomChars.charAt(Math.floor(Math.random() * randomChars.length))
}
return result
}
onPressAppleLogin = async () => {
const rawNonce = this.getRandomString(20);
const state = this.getRandomString(20)
appleAuthAndroid.configure({
clientId: 'co.myexampleapp.signinwithapple',
redirectUri: 'https://my-example-app.firebaseapp.com/__/auth/handler',
responseType: appleAuthAndroid.ResponseType.ALL,
scope: appleAuthAndroid.Scope.ALL,
nonce: rawNonce,
state,
});
const response = await appleAuthAndroid.signIn();
const appleCredential = await firebase.auth.AppleAuthProvider.credential(response.id_token, rawNonce)
const appleUserCredential = await firebase.auth().signInWithCredential(appleCredential) // error happens here!
}
THE END
二维码