4 L*_*ver 5 android firebase react-native firebase-authentication invertase
我正在使用 Apple 实现登录。我可以成功看到Apple登录页面。我输入正确的凭据。它应该能够根据 Apple 的返回值登录/注册 Firebase。
但是我收到了这个错误Error: The supplied auth credential is malformed, has expired or is not currently supported。Firebase 方面一定有问题吗?onPressAppleLogin逻辑上可以参考下面的函数。非常感谢!
我做了什么:
在 Firebase 中
在 developer.apple.com 中
Sign In with Apple 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!
}
Run Code Online (Sandbox Code Playgroud)
小智 1
初始化凭据时出现某种错误。
可能会出现三种类型的错误:
重要检查您是否为 Apple ID 启用了第三方访问。
| 归档时间: |
|
| 查看次数: |
192 次 |
| 最近记录: |