Search code examples
flutterdartgoogle-drive-api

Flutter: unable to signin using a Google account


  1. I am NOT using Firebase
  2. I am still in early developer phase, so not even tried to publish at all on Play Store
  3. My goal is to ask user to login to allow to upload photos to user's google drive.
  4. This question is not duplicated due the fact that almost 100% of questions/answers are related to Firebase.

My code is the following.

Please note: I ask user to login to allow to upload photos to user's Google drive.

import 'dart:developer';

import 'package:google_sign_in/google_sign_in.dart';

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

class AuthManager {
  static Future<GoogleSignInAccount?> signIn() async {
    try {
      final account = await _googleSignIn.signIn();
      log('account: ${account?.toString()}', name: 'AuthManager');
      return account;
    } catch (error) {
      log('signIn error:', name: 'AuthManager');
      log(error.toString(), name: 'AuthManager');
      return null;
    }
  }

  static Future<void> signOut() async {
    try {
      _googleSignIn.disconnect();
    } catch (error) {
      print(error);
    }
  }

  static Future<bool> isSignedIn() async {
    return _googleSignIn.isSignedIn();
  }
}

The error logged is

[AuthManager] signIn error:
[AuthManager] PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)

I know that error number 10 is 'developer error', due to something misconfigured.

But what!!?!?

WHAT I HAVE ALREADY TRIED

  1. I generated a key store for my app

    My app is being signed in debug mode.

    Nothing changes, same exception

  2. I created a oauth client for my app using package name and sha1 read from the generated keystore

    I do not know how will Goggle login connect my flutter app with this oauth credential

    Nothing changes, same exception number 10


Solution

  • We found the only problem was to publish OAuth page.

    1. There is absolutely no need to setup something in Firebase
    2. There is no need to create and download json credentials
    3. Simply prepare OAuth page for publishing

    This 3rd step requires signing the app and building it for release

    Having release apk + rightly signed + OAuth page published allowed our app's users to login with any Google Account properly