Flutter Google Sign-in, stuck after selecting account

Viewed 1351

I am running into issue trying to signin to Firebase with Google Sign-in in my Flutter app.

I've seen two other posts about this, but no answers that resolve it for myself. I am using Google Sign-in provider in flutter, google_sign_in: ^5.1.0, Flutter ver 2.2.1

I have followed the instructions on generating/adding the Sha-1, Sha-256 keys to my firebase project. Prior to that , I was getting an API exception. I added the keys, downloaded the latest google-json file to my android folder and got beyond that error. Now, when I click to Sign-in, I get the account selection screen.

enter image description here

I select my account, and then I hit a white page with endless spinner.

enter image description here

Here is the login code I'm running.

GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: <String>[
    'email',
    'https://www.googleapis.com/auth/contacts.readonly',
  ],
);

  Future<void> _handleGoogleSignIn() async {
    try {
      GoogleSignInAccount? googleSignInAccount =
          await _googleSignIn.signIn();

      GoogleSignInAuthentication? googleSignInAuthentication =
          await googleSignInAccount?.authentication;
    

      final AuthCredential credential = GoogleAuthProvider.credential(
        accessToken: googleSignInAuthentication?.accessToken,
        idToken: googleSignInAuthentication?.idToken,
      );

      final UserCredential user = await _auth.signInWithCredential(credential);  
    } catch (error) {
      print('in error block');
      print(error);
    }
  }

In doing some debug, it doesn't seem to get beyond the initial line:

 GoogleSignInAccount? googleSignInAccount =
          await _googleSignIn.signIn();

But I don't get any error, any warning, nothing...just a spinner that sits indefintely. Any ideas on how to solve this, or at minimum , debug this without getting an error? Thx

1 Answers

After digging further, I found he answer on the same bug reported on the Flutter github account.

https://github.com/flutter/flutter/issues/89169

The solution:

In the following code snippet (which is defined as default setup)

GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: [
    'email',
    'https://www.googleapis.com/auth/contacts.readonly',
  ],
);

Change https://www.googleapis.com/auth/contacts.readonly (restricted scope) to https://www.googleapis.com/auth/userinfo.profile (non-restricted scope).

After that, OAuth screen will proceed with sign in.

Related