Flutterfire: [firebase_auth] Google Sign in returns null id token on web

Created on 8 Apr 2020  路  8Comments  路  Source: FirebaseExtended/flutterfire

Describe the bug
I'm having an error only on flutter web when trying to login. Android and iOS works fine.
Error is:

Error: credential failed: First argument "idToken" must be a valid string or a valid object or null.

To Reproduce
Try to login on https://demo.dalk.fr

Expected behavior
I don't know why google_sign_in is returning an empty GoogleSignInAuthentication instead of null when trying signInSilently. signIn method is doing the same without even trying to login

Additional context
google_sign_in 4.4.1
firebase_auth 0.15.5+3
flutter 1.16.3-pre.56

customer-response web auth needs-repro bug

Most helpful comment

Got this same issue.

I think that the signInSilently() isn't working as advertised on web. Docs say that it returns a "successful sign in or null if there is no previously authenticated user"

But I'm getting a GoogleSignInAccount with null fields, which is causing other checks in my code to fail. Seems to require googleSignIn.signOut() to get back into correct state.

I experienced this issue when moving from debug to release builds. I.E. Signed in using a debug web build, then redeployed got issue on release build.

``` GoogleSignInAccount account = googleSignIn.currentUser;
if (account == null) {

  // signInSilently() Docs say...
  //
  /// Returned Future resolves to an instance of [GoogleSignInAccount] for a
  /// successful sign in or `null` if there is no previously authenticated user.
  account = await googleSignIn.signInSilently();
}

log.info("google account _getSignedInAccount: $account");
// logs... google account _getSignedInAccount: GoogleSignInAccount:{displayName: null, email: null, id: null, photoUrl: null}

// fix for bug https://github.com/FirebaseExtended/flutterfire/issues/2323
if (account != null && account.id == null) {
  account = null;
  googleSignIn.signOut();
}

return account;

```

All 8 comments

A bit mode information:
flutter run -d chrome --web-hostname localhost --web-port 7357 work and I manage to sign in

flutter run -d chrome --web-hostname localhost --web-port 7357 --release doesn't work and give me Error: credential failed: First argument "idToken" must be a valid string or a valid object or null.

look like something is wrong with the release mode

Did you add a "web" application client to your firebase project ?
After you have to add the initialisation to the index.html

Yes on firebase I have 3 apps, android, iOS and web. And I copy paste the initialization like:


<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="/__/firebase/7.13.2/firebase-app.js"></script>

<!-- Add Firebase products that you want to use -->
<script src="/__/firebase/7.13.2/firebase-auth.js"></script>
<script src="/__/firebase/7.13.2/firebase-firestore.js"></script>


<!-- Initialize Firebase -->
<script src="/__/firebase/init.js"></script>
<script src="main.dart.js" type="application/javascript"></script>

Hi @jaumard
Did you add google-signin-client_id in your head in your index.html?

  <meta name="google-signin-client_id" content="<your client ID>" />

Please check this web integration and you might need to whitelist your localhost too for local testing

Thank you

Hello @TahaTesser !

Yes I have it, and I have whitelisted both my domain and localhost, like I said it's working fine on debug mode and I'm able to login. But on release mode it doesn't work, both online and local.

Got this same issue.

I think that the signInSilently() isn't working as advertised on web. Docs say that it returns a "successful sign in or null if there is no previously authenticated user"

But I'm getting a GoogleSignInAccount with null fields, which is causing other checks in my code to fail. Seems to require googleSignIn.signOut() to get back into correct state.

I experienced this issue when moving from debug to release builds. I.E. Signed in using a debug web build, then redeployed got issue on release build.

``` GoogleSignInAccount account = googleSignIn.currentUser;
if (account == null) {

  // signInSilently() Docs say...
  //
  /// Returned Future resolves to an instance of [GoogleSignInAccount] for a
  /// successful sign in or `null` if there is no previously authenticated user.
  account = await googleSignIn.signInSilently();
}

log.info("google account _getSignedInAccount: $account");
// logs... google account _getSignedInAccount: GoogleSignInAccount:{displayName: null, email: null, id: null, photoUrl: null}

// fix for bug https://github.com/FirebaseExtended/flutterfire/issues/2323
if (account != null && account.id == null) {
  account = null;
  googleSignIn.signOut();
}

return account;

```

 // fix for bug https://github.com/FirebaseExtended/flutterfire/issues/2323
    if (account != null && account.id == null) {
      account = null;
      googleSignIn.signOut();
    }

this doesn't fix anything on my side, because even by doing the full signOut, the signIn still return an empty object. So I just can't sign in at all on web :(

Hey 馃憢

Our rework of the firebase_auth plugin as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features. Please could you try the new version and see if this is still an issue for you? If it is then please submit a new up to date GitHub issue or perhaps raise this issue on the repo for the Google Sign-in plugin as this looks like an issue there rather than with Firebase.

For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration

Was this page helpful?
0 / 5 - 0 ratings