Repository: flutter
Issue: google_sign_in - com.google.android.gms.common.api.ApiException: 10
Labels: platform-android,d: api docs,p: google_sign_in,package,team-ecosystem,P2,triaged-ecosystem

Is there an existing issue for this?

- [x]  I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [x]  I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

After reading through countless similar issues
e.g.:

- https://stackoverflow.com/questions/61541415/flutter-platformexceptionsign-in-failed-com-google-android-gms-common-api-ap
- https://stackoverflow.com/questions/54557479/flutter-and-google-sign-in-plugin-platformexceptionsign-in-failed-com-google
- https://github.com/flutter/flutter/issues/75224

and other documentation, changing my Firebase configuration, google-services.json, creating and recreating countless Google Cloud credentials, I have finally decided to post my issue here in hopes of help from others.

My Flutter app is supposed to connect with the Google Calendar of the user logging in, to synchronize their events in their calendar across their devices.

This requires the sensitive scopes:

```dart
static const List<String> scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events'];
```

Secondly, to sign in with google, I tried using https://pub.dev/packages/googleapis_auth, but after that failed due to Googles migration away from loopback URLs, I found https://pub.dev/packages/extension_google_sign_in_as_googleapis_auth, which uses https://pub.dev/packages/google_sign_in to let the user sign in, and then provide me with an AuthClient.

Trying this out successfully opens a dialog to the user, asking them, which Google Account they would like to sign in with, but upon selecting any, I get the (now dreaded) ```com.google.android.gms.common.api.ApiException: 10```

Through reading issues others had with Google oAuth, I found the following, leading me to my current configuration:

## Getting the certificates
- I got the playstore signing and playstore upload certificate hashes from the Play Console
- The debug certificate hashes were found using ```gradlew signingReport```

## Firebase:
- Both the SHA1 and SHA256 hashes have to be uploaded for each certificate
- I added that for the playstore signing, playstore upload, and my apps debug certificate
- I re-downloaded the google-services.json and added it to my app
- The support email was set
- Flutter clean was run before cold starting the app

## Google Cloud:
- All 3 of these certificates SHA1 hashes have a separate Android oAuth credential
- I decided to test it by using my debug certificate, so I downloaded the debug clientId and implemented it in my code:

```dart
GoogleSignIn _googleSignIn = GoogleSignIn(
  clientId: debugClientId, // Technically unused
  serverClientId: debugClientId,
  forceCodeForRefreshToken: true,
  scopes: scopes,
);
```

- The consent dialog had to be setup properly, which I did by filling out all fields whilst keeping the dialog in testing mode, to prevent it from requiring verification
- The consent dialog, since it is in testing mode, required me to add all emails which it would be enabled for, which I did for the emails that I would be clicking in the sign in with Google dialog

## Actually signing in:
- The app was built
- I wait until the appropriate time to ask the user for permission
- The sign in with Google dialog was called using the below dart code:

```dart
GoogleSignInAccount? currentUser = await _googleSignIn.signIn()
```

However, this just yields the issue as described above, here with its complete StackTrace:

```
I/flutter ( 6057): PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)
I/flutter ( 6057): #0      GoogleSignInApi.signIn (package:google_sign_in_android/src/messages.g.dart:221:7)
I/flutter ( 6057): <asynchronous suspension>
I/flutter ( 6057): #1      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:278:30)
I/flutter ( 6057): <asynchronous suspension>
I/flutter ( 6057): #2      GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:431:5)
I/flutter ( 6057): <asynchronous suspension>
I/flutter ( 6057): PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)
I/flutter ( 6057): #0      GoogleSignInApi.signIn (package:google_sign_in_android/src/messages.g.dart:221:7)
I/flutter ( 6057): <asynchronous suspension>
I/flutter ( 6057): #1      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:278:30)
I/flutter ( 6057): <asynchronous suspension>
I/flutter ( 6057): #2      GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:431:5)
I/flutter ( 6057): <asynchronous suspension>
```

At this point, I am considering canceling the feature entirely and staying with local calendars, as it is not a core feature, but this has to work somehow, right?

Flutter doctor
<details>
[√] Flutter (Channel stable, 3.13.3, on Microsoft Windows [Version 10.0.25336.1010], locale en-GB)
    • Flutter version 3.13.3 on channel stable at C:\Users\Konstanius\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2524052335 (8 weeks ago), 2023-09-06 14:32:31 -0700
    • Engine revision b8d35810e9
    • Dart version 3.1.1
    • DevTools version 2.25.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\Konstanius\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.5.0)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.5.33414.496
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] IntelliJ IDEA Ultimate Edition (version 2023.2)
    • IntelliJ at C:\Users\Konstanius\AppData\Local\Programs\IntelliJ IDEA Ultimate
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 232.10072.19

[√] VS Code (version 1.79.0)
    • VS Code at C:\Users\Konstanius\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • RMX1921 (mobile)  • abb55705 • android-arm64  • Android 11 (API 30)
    • Windows (desktop) • windows  • windows-x64    • Microsoft Windows [Version 10.0.25336.1010]
    • Chrome (web)      • chrome   • web-javascript • Google Chrome 118.0.5993.118
    • Edge (web)        • edge     • web-javascript • Microsoft Edge 120.0.2172.1

[√] Network resources
    • All expected network resources are available.

• No issues found!
</details>