我尝试在Flutter Web中与Google实施登录。我使用GoogleSignn 4.1.1和Firebase Auth 0.15.4。我没有收到任何错误消息。它只是不会弹出。
<meta>
标签上添加了google-signin-client_id
final FirebaseAuth _auth = FirebaseAuth.instance;
FirebaseUser user = await _auth.currentUser();
if (user != null) {
log.d('alreadyLoggedIn');
} else {
final GoogleSignIn _googleSignIn = GoogleSignIn(clientId: Constants.GOOGLE_SIGN_IN_CLIENT_ID);
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await _auth.signInWithCredential(credential);
user = await _auth.currentUser();
assert(user.email != null);
assert(user.displayName != null);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
}
return user;
}
我希望有人知道如何解决此问题。
您是否已遵循此页面上的所有说明(包括将OAuth ID添加到index.html中?https://pub.dev/packages/google_sign_in_web
您从https://console.developers.google.com/apis/credentials获得了CLIENT ID
您还必须像这样从终端运行,才能在localhost上通过调试运行:
flutter run -d chrome --web-hostname localhost --web-port 5000
默认的授权端口是5000,您可以在获得CLIENT ID的同一页面上添加其他URI(例如,8764367243864-987523.apps.googleusercontent.com),该页面位于“ JavaScript授权来源”下https://console.developers.google.com/apis/credentials)