Overview
Google Sign-In allows users to authenticate using their Google accounts. This guide covers platform-specific configuration for Android and Web. Implementation Location:lib/services/auth_service.dart:66
Prerequisites
- Firebase project set up (see Firebase Setup)
- Google Sign-In enabled in Firebase Console
- Flutter app with
google_sign_inpackage
Dependencies
Ensure these packages are in yourpubspec.yaml:
pubspec.yaml
Firebase Console Configuration
Enable Google Sign-In Provider
- Open Firebase Console
- Select your project (
aplicacion-trello) - Go to Authentication > Sign-in method
- Click on Google provider
- Toggle Enable
- Set project support email
- Click Save
Configure OAuth Consent Screen
- Go to Google Cloud Console
- Select your Firebase project
- Navigate to APIs & Services > OAuth consent screen
- Choose External user type (or Internal for Google Workspace)
- Fill in required fields:
- App name:
App Tareas - User support email: your email
- Developer contact email: your email
- App name:
- Click Save and Continue
- Skip scopes (default scopes are sufficient)
- Add test users if in testing mode
Android Configuration
Getting SHA-1 Fingerprint
The SHA-1 fingerprint is required for Google Sign-In on Android.Adding SHA-1 to Firebase
Navigate to Project Settings
- Open Firebase Console
- Click the gear icon > Project settings
- Scroll to Your apps section
- Select your Android app (
com.example.app_tareas)
Add SHA-1 Fingerprints
- Scroll to SHA certificate fingerprints
- Click Add fingerprint
- Paste your debug SHA-1
- Click Add fingerprint again
- Paste your release SHA-1
- Click Save
Android Manifest Configuration
Verify yourandroid/app/src/main/AndroidManifest.xml:
AndroidManifest.xml
Build.gradle Configuration
Ensure Google Services plugin is applied:android/app/build.gradle
Web Configuration
Get Web Client ID
- Go to Google Cloud Console
- Select your Firebase project
- Navigate to APIs & Services > Credentials
- Find “Web client (auto created by Google Service)”
- Copy the Client ID (ends with
.apps.googleusercontent.com)
Configure Google Sign-In for Web
Update your
web/index.html to include Google Sign-In meta tag:web/index.html
Implementation Code
Here’s the complete Google Sign-In implementation fromlib/services/auth_service.dart:66:
lib/services/auth_service.dart
Usage in UI
Implement Google Sign-In button in your login screen:lib/ui/screens/login_screen.dart
Testing Google Sign-In
Test on Android Device/Emulator
- Google account picker appears
- User can select an account
- Redirects to home screen after authentication
Verify User Data in Firestore
- Open Firebase Console
- Navigate to Firestore Database
- Check the
userscollection - Verify user document was created with correct data
Troubleshooting
PlatformException: sign_in_failed on Android
PlatformException: sign_in_failed on Android
Cause: SHA-1 fingerprint not configured or incorrect.Solution:
- Generate SHA-1 using
keytoolor./gradlew signingReport - Add SHA-1 to Firebase Console
- Download updated
google-services.json - Rebuild the app completely (
flutter clean && flutter run)
Error 10: Developer error on Android
Error 10: Developer error on Android
Cause: OAuth client ID mismatch or missing SHA-1.Solution:
- Verify package name matches:
com.example.app_tareas - Add both debug and release SHA-1 fingerprints
- Wait 5-10 minutes for changes to propagate
- Clear app data and retry
Google Sign-In returns null
Google Sign-In returns null
Possible causes:
- User cancelled sign-in
- Network connectivity issues
- Incorrect OAuth configuration
- Check logs for specific error messages
- Verify internet permission in AndroidManifest.xml
- Test with different Google accounts
Sign-in works in debug but not release
Sign-in works in debug but not release
Cause: Missing release SHA-1 fingerprint.Solution:
- Get release SHA-1 from your release keystore
- Add it to Firebase Console
- Download updated
google-services.json - Rebuild release APK/App Bundle
Web: popup_closed_by_user error
Web: popup_closed_by_user error
Cause: User closed the sign-in popup.Solution: This is normal behavior. Handle it gracefully in your UI.
iOS: No such module 'GoogleSignIn'
iOS: No such module 'GoogleSignIn'
Solution:
Security Best Practices
- Never expose OAuth secrets: Keep your OAuth client secrets secure
- Use HTTPS: Ensure all authorized domains use HTTPS
- Validate user data: Always validate and sanitize user data from Google
- Implement rate limiting: Prevent abuse by implementing rate limits
- Handle token refresh: Properly handle expired tokens and refresh logic
- Log security events: Monitor sign-in attempts and failures
Next Steps
- Set up Firebase Storage
- Configure Firestore Security Rules
- Implement additional authentication methods (Apple, Facebook, etc.)