π¬ fz_google_oauth2
A Flutter package for Google OAuth2 authentication to get access to Google APIs , login And. contain Custom Interceptors For Refresh Token
π Table of Contents
Screens
![]() |
![]() |
|---|
Features
- π Login And Get Access To Google APIs
- π Custom Interceptors For Refresh Token
- π Complete Google OAuth2 Flow
Getting Started
- Add dependency:
In your
pubspec.yaml:
dependencies:
fz_google_oauth2: ^0.0.2
Install PackageIn your project:
flutter pub get
Android Configuration:In your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
in /android/app/build.gradle
minSdk = 24
// Prefered
compileSdk = 34
iOS Configuration:No additional configuration is required for iOS.:
Usage
Hereβs a complete example showing how to use
the fz_google_oauth2 package to get access to Google APIs and login.
usage google_oauth2
final result = await
FzGoogleOauth2Services.login
(
tenantId: "YOUR_TENANT_ID",
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
scope: "YOUR_SCOPE",
email: _emailController.text,
password: _passwordController.text,
);
if (result != null) {
debugPrint("result: $result");
SnackBar snackBar =
SnackBar(content: Text("Your Token is ${result['access_token']}"));
// SnackBar(content: Text("Your Token is ${result['refresh_token']}"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
Custom Interceptors For Refresh Token
/// Generate Refresh token when expired token
/// By custom indicator
/// If you want to generate refresh token when expired token
/// in your app, you can use this method
/// using Dio interceptors
void generateCustomTokenWhenExpiredTokenByCustomIndicator() async {
InterceptorsWrapper customInterceptors =
FzGoogleOauth2Services.getCustomInterceptorsForRefreshToken(
tenantId: "YOUR_TENANT_ID",
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
scope: "YOUR_SCOPE",
email: _emailController.text,
password: _passwordController.text,
getToken: () async {},
saveToken: (String token) async {},
);
//then you can use your custom interceptors in your dio
Dio dio = Dio();
dio.interceptors.add(customInterceptors);
//then you can use your custom interceptors in your dio
}
Example_Full_Code
You Can Find The Full Code Here
Dependencies Used
This package uses (You do not have to import them):
dio:
Before using this example directly in a Flutter app, don't forget to add the fz_google_oauth2
to your pubspec.yaml file.
You can try out this example by replacing the entire content of main.dart file of a newly created
Flutter project.
About the Developer
Hello! π I'm Fady Zaher, a Mid Level Flutter Developer with extensive experience in building high-quality mobile applications.
- π§ Email: fedo.zaher@gmail.com
If you like this package, feel free to βοΈ the repo and share it!
π License MIT License
Copyright (c) 2025 Fady Zaher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

