Authenticate with Firebase Using Google Sign-In
To enable Google Sign-In authentication in your News App, follow these steps:
-
Open your Firebase console.
-
Go to Authentication and select the Sign-in method tab.
-
Find the Google provider and enable it. This will automatically set up Google sign-in.


-
Download and install JDK x64 Installer from Oracle's website and set JAVA_HOME by following these instructions if you haven't done so yet.
-
In Android Studio, right-click on the android folder, then right-click on gradlew and select "Open In > Terminal" as shown below:

-
In the terminal, enter the command to generate a debug SHA1 key. Copy this key and add it to your Firebase console.


-
Press the save button to enable Google authentication in your app.
With these settings in place, users will be able to sign into your News App using their Google accounts.
Configure Android
- Update your
android/app/build.gradlefile to include Google Sign-In dependencies:
dependencies {
implementation 'com.google.android.gms:play-services-auth:20.3.0'
// Other dependencies
}
- Make sure your SHA-1 fingerprint is registered in the Firebase project settings
Configure iOS
- Open your iOS project in Xcode
- Update the
Info.plistfile to include necessary URL schemes for Google Sign-In - Configure the
GoogleService-Info.plistfile
Add Package Dependencies
- Add the required packages to your
pubspec.yamlfile:
dependencies:
firebase_auth: ^latest_version
google_sign_in: ^latest_version
- Run
flutter pub getto install these dependencies
Implementation Example
Here's a simple example of how to implement Google Sign-In:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
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);
}
Test Google Sign-In thoroughly on both Android and iOS platforms to ensure a smooth user experience.