问题
This is my pubspec.yaml. I'm using Flutter:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
shared_preferences: ^0.4.2
json_serializable: ^1.2.1
camera: ^0.2.3
path_provider: ^0.4.1
simple_permissions: ^0.1.6
share: ^0.5.3
#Google Sign_In
firebase_auth: ^0.5.20
google_sign_in: ^3.0.5
I cannot authenticate with the Google Sign In method. The window shows up normally and after my app throws a error:
PlatformException(sign_in_failed, Status{statusCode=CANCELED, resolution=null}, null)
Haven't found any solutions online, can someone help me out?
The following is my _signIn() method
Future<FirebaseUser> _signIn() async {
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
GoogleSignInAuthentication gSA = await googleSignInAccount.authentication;
FirebaseUser user = await auth.signInWithGoogle(
idToken: gSA.idToken, accessToken: gSA.accessToken);
print("User Name : ${user.displayName}");
return user;
}
My code crashes after I call GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn(); so my guess was, that my setup was wrong.
This is how I call the _signIn()
MaterialButton(
child: Text("Google Sign-In"),
onPressed: (){
_signIn()
.then((FirebaseUser user) => print(user))
.catchError((e) => print(e));
},
),
I already deleted the Firebase-Project on the google dev console online and created a new one. Also I tried the anonymous login -> worked fine
Any help is appreciated
回答1:
Okay, so I managed to fix this problem with using a APK in release mode!
What you have to do:
Build your app in release mode and add the SHA1 or SHA256 to your firebase project.
If you don't know how to prepare your app for release you can do this quickly.
回答2:
I just ran into the same issue. This is how I solved it.
1) Get your SHA1 certificate key. (see https://developers.google.com/android/guides/client-auth)
2) Place the SHA1 key in your Firebase console
3) Rebuild your flutter App and try again. It should be working now.
来源:https://stackoverflow.com/questions/52446960/flutter-firebase-auth-google-sign-in-fail-to-login-with-statuscode-canceled