我试图使我的应用程序的网页版本在颤栗。在android和ios上的移动版本中,使用谷歌凭证登录都是完美的。在网页颤振中,我正确地得到了idToken,但是accessToken是空的。
我遵循了这个视频中的步骤: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;
}
}发布于 2020-08-21 18:31:16
昨晚我开了一个问题 on GitHub,得到了一个答复:
嘿,请更新到firebase_auth:^0.18.0+1 -有一个错误的断言是固定的。最新版本可以在这里看到:https://firebase.flutter.dev/docs/migration/#2-update-firebase-plugins
澄清一下,问题不在于accessToken是空的,而是它不一定是非空的。错误是,有一个断言来检查( idToken或accessToken )是否为空,但实际上它检查和都不是空的。
为了完整起见,这里是修复此错误的确切行更改。注意它们是如何从检查accessToken != null && idToken != null更改为accessToken != null || idToken != null的。
https://stackoverflow.com/questions/63431244
复制相似问题