我的 Flutter Web 应用程序遇到问题,在使用 Google 登录时无法检索 Google ID 令牌。它始终返回 null,我尝试了各种解决方案但没有成功。这是我的方法
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: <String>['email', 'openid'],
);
Future<UserCredential?> signInWithGoogle() async {
try {
googleSignIn.signOut();
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
if (googleUser != null) {
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final OAuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
return await _auth.signInWithCredential(credential);
} else {
print('No user');
}
} catch (e) {
print("Error signing in with Google: $e");
return null;
}
return null;
}
我检查了我的谷歌控制台、OAuth 密钥设置和一堆其他东西,但它们都不起作用。我开始怀疑这个问题是否是Flutter SDK本身的问题,目前还没有解决方案。
让我知道你的想法
问题是
googleSignIn.signIn()
不再在网络上返回 idToken。
切换到 googlesignIn.signInSilently()
;