A Flutter application demonstrating Google Sign-In integration with JWT token authentication.
- Google Sign-In Authentication
- JWT Token Management
- Persistent Authentication State
- Material Design UI
- Secure Token Storage
-
Flutter Setup
flutter pub get
-
Google Sign-In Configuration
a. Go to the Google Cloud Console
b. Create a new project or select an existing one
c. Enable the Google Sign-In API
d. Create OAuth 2.0 credentials:
- Create OAuth client ID
- Select "Web application" as the application type
- Add authorized redirect URIs
- Download the client configuration file
-
Backend Configuration
Update the
_apiUrlinlib/services/auth_service.dartwith your backend API URL:static const String _apiUrl = 'YOUR_API_URL';
-
Running the App
flutter run
lib/
├── main.dart # App entry point and navigation setup
├── screens/
│ └── login_screen.dart # Login page UI
└── services/
└── auth_service.dart # Authentication logic
- User clicks "Sign in with Google" button
- Google Sign-In flow is initiated
- After successful Google authentication:
- Backend receives Google token
- Backend validates token and creates JWT
- App stores JWT for future requests
- User is redirected to home screen
- JWT is used for subsequent API requests
- JWT tokens are stored securely using SharedPreferences
- HTTPS is used for all API communications
- Google Sign-In implementation follows OAuth 2.0 best practices
- google_sign_in: ^6.1.5
- http: ^1.1.0
- jwt_decoder: ^2.0.1
- shared_preferences: ^2.2.1
- Make sure to configure your Google Cloud Console project properly
- Update the backend API URL before running the app
- Handle token expiration and refresh tokens as needed
- Implement proper error handling in production