Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase Auth / Google_sign_in fail to login with statuscode=CANCELED

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

like image 300
JanMer Avatar asked Dec 17 '22 20:12

JanMer


1 Answers

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.

like image 137
Gainz Avatar answered Dec 28 '22 09:12

Gainz