gpt4 book ai didi

flutter - Web Flutter 中 GoogleSignInAuthentication accessToken 的 accessToken 为 null

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

我正在尝试使我的应用程序的 web 版本在 flutter 中可用。在移动版本中,无论是 android 还是 ios,使用 google 凭据登录都可以完美运行。在 web flutter 中,我正确获取了 idToken,但 accessToken 为空。
我按照此视频中的步骤操作:https://www.youtube.com/watch?v=0HLt1TYA600&list=LLe08PibNO0_PFjUVIu5WcxQ&index=3&t=1681s

Future<User> signInWithGoogle() async {
final googleSignIn = GoogleSignIn();

try {
final GoogleSignInAccount googleSignInAccount =
await googleSignIn.signIn();
if (googleSignInAccount != null) {
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
print(">>> accessToken");
print(googleSignInAuthentication.accessToken);
print(">>> idToken");
print(googleSignInAuthentication.idToken);
if (googleSignInAuthentication.accessToken != null &&
googleSignInAuthentication.idToken != null) {
final AuthCredential credential = GoogleAuthProvider.getCredential(
idToken: googleSignInAuthentication.idToken,
accessToken: googleSignInAuthentication.accessToken,
);

final AuthResult authResult =
await FirebaseAuth.instance.signInWithCredential(credential);

final FirebaseUser user = authResult.user;
return _userFromFirebase(user);
} else {
throw PlatformException(
code: 'ERROR_MISSING_GOOGLE_AUTH_TOKEN',
message: 'Missing Google Auth Token',
);
}
} else {
throw PlatformException(
code: 'ERROR_ABORTED_BY_USER',
message: 'Sign in aborted by user',
);
}
} catch (error) {
return null;
}
}

最佳答案

我开了一个 issue昨晚在 GitHub 上得到了答案:

Hey, please update to firebase_auth: ^0.18.0+1 - there was a bug with the assertion that was fixed.Latest versions can be seen here: https://firebase.flutter.dev/docs/migration/#2-update-firebase-plugins


澄清一下,问题不在于 accessToken是空的,它不一定非空。错误是有断言检查是否 要么 idTokenaccessToken不为空,但它确实会检查 两者 不为空。
为完整起见, here是修复此错误的确切行更改。注意他们是如何从检查 accessToken != null && idToken != null 改变的至 accessToken != null || idToken != null .

关于flutter - Web Flutter 中 GoogleSignInAuthentication accessToken 的 accessToken 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63431244/

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