2

I'm getting this error when trying to use Google Sign-in with Firebase Emulators

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/unknown] An internal error has occurred. [ The Auth Emulator only support sign-in with google.com using id_token, not access_token. Please update your code to use id_token.

My sign-in code is copied almost verbatim from Firebase docs

import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

Future<UserCredential> signInWithGoogle() async {
  // Trigger the authentication flow
  final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();

  // Obtain the auth details from the request
  final GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;

  // Create a new credential
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth?.accessToken,
    idToken: googleAuth?.idToken,
  );

  // Once signed in, return the UserCredential
  return await FirebaseAuth.instance.signInWithCredential(credential);
}

This only shows up when hooked up to Emulator suite and not when using real Firebase instance.

Is there a workaround or fix?

Flutter Doctor output

[✓] Flutter (Channel stable, 3.16.8, on Ubuntu 22.04.3 LTS 6.5.0-21-generic, locale en_US.UTF-8)
    • Flutter version 3.16.8 on channel stable at /home/starleaf1/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    �� Framework revision 67457e669f (6 weeks ago), 2024-01-16 16:22:29 -0800
    • Engine revision 6e2ea58a5c
    • Dart version 3.2.5
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/starleaf1/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/starleaf1/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2023.1)
    • Android Studio at /home/starleaf1/android-studio
    • Flutter plugin version 78.0.1
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /home/starleaf1/android-studio
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version unknown)
    • VS Code at /snap/code/current
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    ✗ Unable to determine VS Code version.

[✓] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Linux (desktop)              • linux         • linux-x64      • Ubuntu 22.04.3 LTS 6.5.0-21-generic
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 121.0.6167.184

[✓] Network resources
    • All expected network resources are available.

• No issues found!

The Firebase integration was initialized using FlutterFire CLI

3
  • Just putting it here in case someone comes across the same problem as me, but this question hasn't been answered by then. So far, my workaround involves making a new node project, copying the Firebase config and rules to that new project, and then replicating the operation in JavaScript. It's barbaric but it works.
    – starleaf1
    Commented Feb 27, 2024 at 18:40
  • What do you mean by replacing the operation in javascript? I'm having the same issue. Commented Mar 20, 2024 at 15:07
  • @RafaelZasas I didn't say "replace", I said "replicate". I couldn't get the emulator to work so I rewrite relevant parts of the project in JavaScript and run it via Node.js. I mainly want to debug my security rules so this way I can achieve my goal.
    – starleaf1
    Commented Mar 22, 2024 at 7:38

2 Answers 2

0
  • Put google-services.json on android/app
  • On android/build.gradle add on dependencies:
dependencies {
  classpath 'com.google.gms:google-services:4.3.15'
  ...
}
  • On android/app/build.gradle add before android:
apply plugin: 'com.google.gms.google-services'
    
android {
  ...
-2
  1. first off all check the json file in your android/app/google-services.json

enter image description here

  1. clarify in firebase account google signing enabled or not?

enter image description here

  1. lastly change the ssh in your firebase console

try this -

./gradlew signingReport 

make sure run the particular command on android directory

1
  • 1. The file exists and there are various credential info in there. Is there anything in particular I should be looking out for? 2. Signing in with Google is enabled. 3. Both the SHA-1 and SHA-256 in Firebase project settings are filled in using the debug key from that command.
    – starleaf1
    Commented Feb 29, 2024 at 14:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.