Simple Google Sign In Authentication in Flutter with Firebase

Shashank
2 min readApr 7, 2024

--

Well, this is very simple to implement Authentication provider. But this article is about using it more simpler and accessible to the new developers.

1. Setting up the Firebase on web

  • Open the firebase website and open up the authentication section
  • Now, after setting up the basis authentication went up to the Sign-In Method
  • Here, click on the Sign-In provider, their in select the Google as the provider
  • As, we can see in the image this authentication requires SHA-1 fingerprint, which can be retrieved from the given command.
keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
  • The password for keystore is “android”. So, enter “android” when “Enter keystore password:” is asked.
  • And paste the SHA-1 Fingerprint from the command line to the project setting of the firebase.
    - Under the Project Overview section select the Project setting, their you will see the space for entering the SHA-1 fingerprint.
  • Now you have done all the set up from the firebase side and we need to only make changes to our flutter project for completing the authentication.

2. Setting up our Flutter project

  • Here, we have to first add some dependencies like
firebase_auth: ^4.19.0
google_sign_in: ^6.2.1
  • These dependencies can be added from the terminal or “pubspec.yaml” file.

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);
}
  • Above is the signInWithGoogle function which you can add to the on press property of button and manage you users sign in.

This article is made with the help of firebase documentation, so for more detailed information you can refer the official firebase documentation here.

Thanks for reading this article, I am open to all the suggestions or feedbacks.

--

--