Flutter Google Sign-In With Firebase Auth

· 5 min read

Google Sign-In is the most requested login option on Android and a common one on iOS. With Firebase Auth, the flow is: the google_sign_in plugin signs the user in with Google and returns an ID token, then Firebase turns that token into a Firebase user. The Dart side is about 20 lines. Most of the work, and most of the bugs, are in console setup and signing keys.

Note that google_sign_in 7 changed the API substantially. Many tutorials still show the old GoogleSignIn().signIn() call, which does not exist in 7. This post uses the current API. It is part of building a Flutter app with Claude Code.

Step 1: enable the provider

In the Firebase console, open Authentication, then the Sign-in method tab, and enable Google. If your app does not have Firebase yet, start with Firebase for Flutter with Claude Code.

Then add the packages:

flutter pub add firebase_auth google_sign_in

Step 2: Android signing keys

Google needs to know which signing certificates belong to your app. Missing or wrong SHA-1 fingerprints are a frequent cause of Android failures; the plugin’s README lists “Missing or incorrect signing SHA for one or more build configurations” among the common configuration errors.

You usually need three SHA-1s on your Firebase Android app:

  1. Debug key. From the android folder run ./gradlew signingReport, or use keytool on ~/.android/debug.keystore with alias androiddebugkey. Google: “The default password for the debug keystore is android.”
  2. Upload key. The keystore you sign release builds with.
  3. Play app signing key. Google: “When using Play App Signing, the upload key certificate will be different than the app signing key certificate.” Find it in Play Console under Release > Setup > App Integrity.

Forgetting the third one is the classic “works locally, fails from the Play Store” bug.

After adding fingerprints, download a fresh google-services.json (or re-run flutterfire configure). The Android plugin README says no IDs are needed in Dart “as long as your google-services.json contains a web OAuth client entry,” which is an oauth_client with client_type: 3. If that entry is missing, add a web app to the Firebase project and download the file again.

Step 3: iOS setup

From the google_sign_in_ios README:

  1. Download a fresh GoogleService-Info.plist after enabling Google sign-in. The README says “Do not put this file in your project”; you only copy values from it.
  2. Add a GIDClientID key to ios/Runner/Info.plist with the CLIENT_ID value.
  3. Add a CFBundleURLTypes entry whose URL scheme is the REVERSED_CLIENT_ID value.
<key>GIDClientID</key>
<string>1234-abcd.apps.googleusercontent.com</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>com.googleusercontent.apps.1234-abcd</string>
    </array>
  </dict>
</array>

Step 4: initialize once

Version 7 requires an explicit setup call. The migration guide: “There is now an explicit initialize step that must be called exactly once, before any other methods.” GoogleSignIn is also now a singleton.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  await GoogleSignIn.instance.initialize();
  runApp(const App());
}

On Android, if you are not relying on google-services.json, pass the web client ID as serverClientId: here. The README calls a missing or wrong serverClientId a common error.

Step 5: sign in

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

Future<UserCredential?> signInWithGoogle() async {
  try {
    final account = await GoogleSignIn.instance.authenticate();
    final idToken = account.authentication.idToken;

    final credential = GoogleAuthProvider.credential(idToken: idToken);
    return await FirebaseAuth.instance.signInWithCredential(credential);
  } on GoogleSignInException catch (e) {
    if (e.code == GoogleSignInExceptionCode.canceled) return null;
    rethrow;
  }
}

What changed from older code:

  • authenticate() replaces signIn() “on platforms that support it.” Check with supportsAuthenticate(); the migration guide says web is the one platform that does not, and uses a rendered button instead.
  • account.authentication is now synchronous, and the API docs say “Currently there is only an idToken.” Firebase only needs the ID token here.
  • Cancellation throws GoogleSignInException with code canceled instead of returning null.
  • Authentication and authorization are separate. If you also need Google API scopes (Drive, Calendar), request them later through account.authorizationClient when the feature needs them.

One Android gotcha: the README warns that some configuration errors make Android’s Credential Manager return “canceled”, and the plugin “has no way to distinguish this case from the user canceling.” If every attempt looks canceled, check SHA-1s and the web client before anything else.

Step 6: watch auth state

Do not track the signed-in user through google_sign_in; version 7 removed currentUser and the guide says the plugin “no longer tracks a single ‘current’ signed in user.” Use Firebase:

FirebaseAuth.instance.authStateChanges().listen((User? user) {
  // null means signed out
});

Firebase’s docs warn not to place this listener “directly inside a widget’s build method.” Expose it through a provider instead (see Riverpod with Claude Code).

Sign out of both:

await GoogleSignIn.instance.signOut();
await FirebaseAuth.instance.signOut();

Account linking and deletion

If you start users anonymously, link Google to the existing user with linkWithCredential rather than signing in fresh, so their data stays. Firebase’s linking guide shows FirebaseAuth.instance.currentUser?.linkWithCredential(credential) and lists a credential-already-in-use error for when that Google account already belongs to another Firebase user; handle it by signing in to that account instead. Firebase also notes that when a user who registered with email later signs in with Google, the provider switches to Google, because Google is treated as a trusted provider.

App Store rules also apply: guideline 5.1.1(v) says “If your app supports account creation, you must also offer account deletion within the app.” With Firebase, user.delete() can fail with requires-recent-login, so reauthenticate with a fresh Google credential and retry. See the account deletion requirement.

If you ship on iOS with Google sign-in, read Guideline 4.8 login services and consider adding Sign in with Apple with Firebase at the same time.

Troubleshooting checklist

  • Every attempt “canceled” on Android: SHA-1s, package name, web OAuth client in google-services.json.
  • Works in debug, fails from Play: Play app signing SHA-1 missing.
  • Works in dev flavor, fails in prod: each flavor’s package name needs its own SHA-1s and config (see Flutter flavors).
  • iOS sign-in fails: check GIDClientID and the reversed client ID URL scheme in Info.plist.
  • “initialize” errors: called twice, or another method called before it.

MobileKit’s auth skill follows this anonymous-first, link-later pattern and checks the signing keys before release.

Sources read on the day this post was written: Firebase: Federated identity and social sign-in (Flutter), google_sign_in on pub.dev, google_sign_in migration guide, google_sign_in_android, google_sign_in_ios, Google: Authenticating your client, Firebase: Manage users (Flutter) and Firebase: Account linking (Flutter).

Questions

Why does Google Sign-In work in debug but fail in my Play Store build?

Google says that with Play App Signing the upload key certificate differs from the app signing key certificate. Add the SHA-1 from Play Console's App Integrity page to your Firebase Android app, along with your debug and upload SHA-1s.

What replaced signIn() in google_sign_in 7?

The migration guide says authenticate replaces the authentication portion of signIn on platforms that support it, and signInSilently was replaced by attemptLightweightAuthentication. You must also call initialize exactly once before any other method.

Do I need Sign in with Apple if I offer Google Sign-In?

Possibly. Apple's guideline 4.8 covers apps that use third-party login services. Check that guideline before submitting to the App Store.

Try it on your next idea

One payment, every update to this major version, and a refund window if it is not for you. Refund policy.