gpt4 book ai didi

firebase - 未找到访问 token 受众中的 OAuth2 客户端 ID

转载 作者:行者123 更新时间:2023-12-03 16:32:22 24 4
gpt4 key购买 nike

首先,我为我糟糕的英语感到抱歉。
我使用 Expo 创建了一个 Android 应用程序。
我通过 Firebase 实现了 Google 登录。
它没有问题。
为了将结果交付给客户,Firebase 项目的所有权移交给了客户。
我将我的权限更改为编辑。
但有一个问题。
firebase.auth().signInWithCredential 函数导致错误。
错误代码和信息如下。
未找到访问 token 受众中的 auth/invalid-credential OAuth2 客户端 ID。
我已经用谷歌搜索了错误消息来解决这个问题,但我无法找到它。
这就是我在 Stack Overflow 上写作的原因。
LoginScreen.js

import React, { useEffect, useState } from 'react';
import { Button, Image, ImageBackground, Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import * as Google from 'expo-google-app-auth';
import firebase from 'firebase'
import { fireAuth, fireStore } from '../Components/FireConfig';
import { screenHeight, screenWidth } from '../Components/Base';
import i18n from 'i18n-js';
import { ActivityIndicator } from 'react-native-paper';
export function LoginScreen({ navigation, route }) {

const [isLoading, setIsLoading] = useState(false)

// var provider = new firebase.auth.GoogleAuthProvider();

function isUserEqual(googleUser, firebaseUser) {
if (firebaseUser) {
var providerData = firebaseUser.providerData;
for (var i = 0; i < providerData.length; i++) {
console.log('providerData[i].providerId', providerData[i].providerId)
console.log('providerData[i].uid', providerData[i].uid)
if (providerData[i].providerId === firebase.auth.GoogleAuthProvider.PROVIDER_ID &&
// providerData[i].uid === googleUser.getBasicProfile().getId()) {
providerData[i].uid === googleUser.user.id) {
// We don't need to reauth the Firebase connection.
return true;
}
}
}
return false;
}

function onSignIn(googleUser) {
// console.log('Google Auth Response', googleUser);
// We need to register an Observer on Firebase Auth to make sure auth is initialized.
var unsubscribe = fireAuth.onAuthStateChanged(function (firebaseUser) {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
if (!isUserEqual(googleUser, firebaseUser)) {
// Build Firebase credential with the Google ID token.
var credential = firebase.auth.GoogleAuthProvider.credential(
//googleUser.getAuthResponse().id_token
googleUser.idToken,
googleUser.accessToken,
)
console.log("credential", credential)
// Sign in with credential from the Google user.
fireAuth
.signInWithCredential(credential)
.then((result) => {
const uid = result.user.uid
if (result.additionalUserInfo.isNewUser) {
fireStore
.collection('users')
.doc(uid)
.set({
google_email: result.user.email,
google_profile_picture: result.additionalUserInfo.profile.picture,
google_locale: result.additionalUserInfo.profile.locale,
google_name: result.additionalUserInfo.profile.name,
created_at: Date.now(),
isPushInfo: false
})
} else {
fireStore
.collection('users')
.doc(uid)
.update({
last_logged_in: Date.now()
})
}
})
.catch((e) => {
console.log(e.code, e.message)
});
} else {
console.log('User already signed-in Firebase.', fireAuth.languageCode);
}
});
}

async function signInWithGoogleAsync() {
setTimeout(() => {
setIsLoading(true)
}, 500)
try {
const result = await Google.logInAsync({
androidClientId : "!!!.apps.googleusercontent.com",
androidStandaloneAppClientId : "@@@.apps.googleusercontent.com",
iosClientId : "###.apps.googleusercontent.com",
iosStandaloneAppClientId : "$$$.apps.googleusercontent.com",
scopes: ['profile', 'email']
});
if (result.type === 'success') {
console.log(result.type)
onSignIn(result)
return result.accessToken;
} else {
setIsLoading(false)
console.log(result)
alert(result)
return { cancelled: true };
}
} catch (e) {
setIsLoading(false)
console.log(e)
alert(e)
return { error: true };
}
}

return (
<View style={styles.container}>
<TouchableOpacity
style={{
alignItems: "center",
justifyContent: "center",
borderRadius: 10,
backgroundColor: "white",
width: screenWidth * 0.8,
height: 50
}}
title="Sign In With Google"
onPress={() => {
signInWithGoogleAsync();
}} >
<Text style={{ color: "#5887f9" }}>{i18n.t('SignInWithGoogle')}</Text>
</TouchableOpacity>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
})
正如您从下面的链接中看到的
https://console.developers.google.com/apis/credentials
app.json
{
"expo":

...

"android": {
"package": "com.mycompany.myapp",
"versionCode" : 2,
"permissions": [
"READ_EXTERNAL_STORAGE",
"READ_INTERNAL_STORAGE",
"WRITE_EXTERNAL_STORAGE",
"ACCESS_FINE_LOCATION",
"INTERNET",
"CAMERA_ROLL",
"CAMERA"
],
"googleServicesFile": "./google-services.json",
"useNextNotificationsApi": true,
"config": {
"googleMobileAdsAppId": "```",
"googleSignIn" :{
"apiKey" : "my apiKey",
"certificateHash" : "11:22:---:11:22"
}
}
}

...

}
}
API key 和 OAuth 2.0 客户端 ID 必须写入链接中的内容。
我期待着您的友好合作。

最佳答案

关于 GitHub 上的这张票:https://github.com/FirebaseExtended/flutterfire/issues/4053 Google 登录和 Firebase 身份验证存在一个核心问题。我联系了 GCP 支持,几个小时后他们修复了它❤️

关于firebase - 未找到访问 token 受众中的 OAuth2 客户端 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64701232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com