9
votes

Using Firebase Google Auth, when a user logs in successfully with their google account, they are not showing on our Firebase Console Authentication->Users screen. Only email/password users are showing up there.

Is there something extra that needs to be done to see the Google Auth users?

3
Please add some code.Alex Mamo
no need to extra steps if your authentication works all goodOussema Aroua
OAuth users (such as Google) will only show in the Firebase console after you sign them into Firebase by calling signInWithCredential(). Until that call they may have signed in with Google, but they have not signed in to Firebase.Frank van Puffelen
Indeed, this was the issue. I was not calling signInWithCredential() anywhere and it was successfully signing into Google, but not through to Firebase.MBU

3 Answers

9
votes

As indicated by Frank, to fully sign into Firebase the call to signInWithCredential() was needed. After implementing this functionality, users signing in with Google showed up in the Firebase console.

5
votes

In Flutter, besides GoogleSignIn, you also need to install firebase_auth package.

https://pub.dev/packages/firebase_auth#-installing-tab-

https://pub.dev/packages/firebase_auth

import 'package:firebase_auth/firebase_auth.dart';

final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;

Future<FirebaseUser> _handleSignIn() async {
  final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  final GoogleSignInAuthentication googleAuth = await googleUser.authentication;

  final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );

  final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
  print("signed in " + user.displayName);
  return user;
}

...

_handleSignIn()
    .then((FirebaseUser user) => print(user))
    .catchError((e) => print(e));
1
votes

Follow the below steps:

  • Trigger the Google 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 GoogleAuthCredential googleCredential = GoogleAuthProvider.credential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );
  • Sign in to Firebase with the Google [UserCredential]

 

final UserCredential googleUserCredential =
    await FirebaseAuth.instance.signInWithCredential(googleCredential);

That's it !!