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

4,607

Solution 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.

Solution 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.

Share:
4,607
JanMer
Author by

JanMer

Hi :)

Updated on December 07, 2022

Comments

  • JanMer
    JanMer over 1 year

    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

  • JanMer
    JanMer over 5 years
    Are you sure you ran into the same issue? My statusCode is CANCELED! It did not work for me.
  • Vincent
    Vincent over 5 years
    If you resolve the problem that way.. it looks like, at least, Gainz's answer was helpful for you to solve the problem. You might solve that problem without being release mode, if you see the description carefully. You might be able to add the SHA thing even you are on the dev mode. Just my personal feel is that you should select Gainz's answer as the answer and add your explain as a comment not the answer.
  • JanMer
    JanMer over 5 years
    @Vincent no, because his solution was not successfull for me.