Flutter application showcasing different authentication methods using Riverpod for state management and dependency injection.
Before getting started, make sure you have the following installed:
- Flutter SDK: >=3.10.0 <4.0.0
- Dart SDK: >=3.10.0 <4.0.0
- IDE: VSCode or Android Studio with Flutter extensions
- Platforms:
- For iOS: Xcode (macOS only)
- For Android: Android Studio or Android SDK
git clone <repository-url>
cd flutter_login_typesflutter pub getThis project supports multiple third-party authentication providers. You need to configure each one you plan to use.
Create a config-keys.json file in the project's root directory with the following structure:
{
"GOOGLE_CLIENT_ID_AND": "<YOUR_GOOGLE_CLIENT_ID_AND>",
"GOOGLE_CLIENT_ID_IOS": "<YOUR_GOOGLE_CLIENT_ID_IOS>",
"GOOGLE_CLIENT_ID_IOS_REV": "<YOUR_GOOGLE_CLIENT_ID_IOS_IN_REVERSE>",
"APPLE_CLIENT_ID": "<YOUR_APPLE_CLIENT_ID>",
"APPLE_REDIRECT_URI": "<YOUR_APPLE_REDIRECT_URI>",
"FACEBOOK_APP_ID": "<YOUR_FACEBOOK_APP_ID>",
"FACEBOOK_CLIENT_TOKEN": "<YOUR_FACEBOOK_CLIENT_TOKEN>",
"FACEBOOK_DISPLAY_NAME": "<YOUR_FACEBOOK_DISPLAY_NAME>",
"TWITTER_API_KEY": "<YOUR_TWITTER_API_KEY>",
"TWITTER_API_SECRET": "<YOUR_TWITTER_API_SECRET>",
"TWITTER_REDIRECT_URI": "<YOUR_TWITTER_REDIRECT_URI>",
"AZURE_TENANT_NAME": "<YOUR_AZURE_TENANT_NAME>",
"AZURE_TENANT_ID": "<YOUR_AZURE_TENANT_ID>",
"AZURE_POLICY_NAME": "<YOUR_AZURE_POLICY_NAME>",
"AZURE_CLIENT_ID": "<YOUR_AZURE_CLIENT_ID>",
"AZURE_REDIRECT_SCHEME": "<YOUR_AZURE_REDIRECT_SCHEME>",
"AZURE_REDIRECT_PATH": "<YOUR_AZURE_REDIRECT_PATH>",
"AZURE_ENDPOINT_URL": "<YOUR_AZURE_ENDPOINT_URL>",
"AUTH0_DOMAIN": "<YOUR_AUTH0_DOMAIN>",
"AUTH0_CLIENT_ID": "<YOUR_AUTH0_CLIENT_ID>",
"AUTH0_SCHEME_AND": "<YOUR_AUTH0_SCHEME_AND>",
"MSAL_TENANT_ID": "<YOUR_MSAL_TENANT_ID>",
"MSAL_CLIENT_ID": "<YOUR_MSAL_CLIENT_ID>",
"MSAL_REDIRECT_SCHEME": "<YOUR_MSAL_REDIRECT_SCHEME>"
}Important: Add config-keys.json to .gitignore to avoid committing sensitive credentials.
The project supports multiple languages. Generate the localization files:
flutter gen-l10nTranslation files are located at:
lib/l10n/arb/directory
# Run with dart-define configuration
flutter run --dart-define-from-file=config-keys.json# iOS
flutter run --dart-define-from-file=config-keys.json -d iPhone
# Android
flutter run --dart-define-from-file=config-keys.json -d android# iOS
flutter build ios --dart-define-from-file=config-keys.json
# Android (App Bundle)
flutter build appbundle --dart-define-from-file=config-keys.json
# Android (APK)
flutter build apk --dart-define-from-file=config-keys.jsonlib/
├── l10n/ # Localization files
│ ├── arb/ # .arb files for translations
│ └── gen/ # Generated localization files
├── core/ # Core application infrastructure
│ ├── client/ # HTTP client configuration
│ ├── config/ # App configuration
│ ├── dependencies/ # Dependency injection setup
│ ├── enum/ # Enumerations
│ ├── notifiers/ # State notifiers
│ ├── repository/ # Data repositories
│ ├── router/ # Navigation and routing
│ ├── services/ # Business logic services
│ ├── theme/ # App theming
│ └── widgets/ # Shared widgets
└── features/ # Feature modules
├── fingerprint_login/ # Biometric authentication
├── home/ # Home screen
├── login_options/ # Login type selection
├── mechanism_login/ # Azure AD B2C / Auth0
├── passcode_login/ # PIN code authentication
├── simple_login/ # Username/Password login
├── third_login/ # Social media authentication
└── totp_login/ # TOTP login variants
├── oauth_totp_login/ # Microsoft (MSAL) + TOTP second factor
├── simple_totp_login/ # Standalone TOTP (no identity provider)
└── totp_options_view.dart # TOTP variant selection screen
Traditional authentication using username and password credentials. This demonstrates:
- Form validation using
formzpackage - Secure credential handling
- Backend integration patterns
Phone number-based authentication with 4-digit verification code. Features:
- Phone number input validation
- PIN code entry with
pinputpackage - Push notification simulation for access code
Biometric authentication using local device capabilities:
- Fingerprint recognition (Android, iOS)
- Face ID (iOS)
- Local authentication with
local_authpackage - Secure storage with
flutter_secure_storage
Social media authentication supporting:
- Google Sign In: OAuth 2.0 authentication
- Apple Sign In: Sign in with Apple ID
- Facebook Login: Facebook authentication
- Twitter Login: Twitter OAuth
Enterprise authentication solutions:
- Azure Active Directory B2C: Microsoft identity platform
- Auth0: Universal authentication platform
Each mechanism supports user/password and social logins within their platforms.
Two variants grouped under the TOTP Login option on the main screen:
Standalone TOTP without a primary identity provider. No config keys required.
Flow:
- App generates a secret key and displays a QR code
- Scan the QR code with any TOTP-compliant authenticator app — Google Authenticator, Microsoft Authenticator, Authy,
1Password, Bitwarden, or any other app that supports the
otpauth://standard - Enter the 6-digit code shown in the app to complete setup
- On subsequent logins, enter the current 6-digit code
Account details used in QR code:
- Issuer:
FlutterLoginTypes - Account:
demo@flutter.dev
Microsoft Sign In as the primary factor, followed by TOTP as the second factor.
Uses flutter_appauth with Azure AD. Requires MSAL_TENANT_ID, MSAL_CLIENT_ID, and MSAL_REDIRECT_SCHEME in
config-keys.json.
Flow:
- Authenticate with your Microsoft account via browser redirect
- On first login: app generates a TOTP secret, displays a QR code to scan with any TOTP-compliant app
- Confirm setup by entering the 6-digit code
- On subsequent logins: enter the current 6-digit code after Microsoft authentication
Option 1: Using GoogleService files (Recommended)
Follow the official integration guide
Option 2: Using dart-define configuration
Add to your config-keys.json:
{
"GOOGLE_CLIENT_ID_AND": "<YOUR_GOOGLE_CLIENT_ID_AND>",
"GOOGLE_CLIENT_ID_IOS": "<YOUR_GOOGLE_CLIENT_ID_IOS>",
"GOOGLE_CLIENT_ID_IOS_REV": "<YOUR_GOOGLE_CLIENT_ID_IOS_IN_REVERSE>"
}Get credentials from Google Cloud Console
Required configuration in config-keys.json:
{
"APPLE_CLIENT_ID": "<YOUR_APPLE_CLIENT_ID>",
"APPLE_REDIRECT_URI": "<YOUR_APPLE_REDIRECT_URI>"
}Resources:
Required configuration in config-keys.json:
{
"FACEBOOK_APP_ID": "<YOUR_FACEBOOK_APP_ID>",
"FACEBOOK_CLIENT_TOKEN": "<YOUR_FACEBOOK_CLIENT_TOKEN>",
"FACEBOOK_DISPLAY_NAME": "<YOUR_FACEBOOK_DISPLAY_NAME>"
}Resources:
Required configuration in config-keys.json:
{
"TWITTER_API_KEY": "<YOUR_TWITTER_API_KEY>",
"TWITTER_API_SECRET": "<YOUR_TWITTER_API_SECRET>",
"TWITTER_REDIRECT_URI": "<YOUR_TWITTER_REDIRECT_URI>"
}Resources:
Required configuration in config-keys.json:
{
"AZURE_TENANT_NAME": "<YOUR_AZURE_TENANT_NAME>",
"AZURE_TENANT_ID": "<YOUR_AZURE_TENANT_ID>",
"AZURE_POLICY_NAME": "<YOUR_AZURE_POLICY_NAME>",
"AZURE_CLIENT_ID": "<YOUR_AZURE_CLIENT_ID>",
"AZURE_REDIRECT_SCHEME": "<YOUR_AZURE_REDIRECT_SCHEME>",
"AZURE_REDIRECT_PATH": "<YOUR_AZURE_REDIRECT_PATH>",
"AZURE_ENDPOINT_URL": "<YOUR_AZURE_ENDPOINT_URL>"
}Resources:
Required configuration in config-keys.json:
{
"AUTH0_DOMAIN": "<YOUR_AUTH0_DOMAIN>",
"AUTH0_CLIENT_ID": "<YOUR_AUTH0_CLIENT_ID>",
"AUTH0_SCHEME_AND": "<YOUR_AUTH0_SCHEME_AND>"
}Note: AUTH0_SCHEME_AND is only required for Android custom schemes.
Resources:
Register an app in Azure Active Directory (not B2C — use the regular Azure AD).
Required configuration in config-keys.json:
{
"MSAL_TENANT_ID": "<YOUR_AZURE_AD_TENANT_ID>",
"MSAL_CLIENT_ID": "<YOUR_AZURE_AD_APP_CLIENT_ID>",
"MSAL_REDIRECT_SCHEME": "<YOUR_REDIRECT_SCHEME>"
}The redirect URI registered in Azure must match: <MSAL_REDIRECT_SCHEME>://auth
Resources:
-
Edit the
.arbfiles inlib/l10n/arb/ -
Add new key/value pairs:
{ "@@locale": "en", "newKey": "New translation", "@newKey": { "description": "Description of the new key" } } -
Regenerate localization files:
flutter gen-l10n
-
Create a new
.arbfile inlib/l10n/arb/:intl_fr.arb # For French -
Update iOS localization in
ios/Runner/Info.plist:<key>CFBundleLocalizations</key> <array> <string>en</string> <string>es</string> <string>fr</string> </array>
-
Regenerate localization files
The project uses very_good_analysis to maintain code quality:
flutter analyzeflutter format .This project uses freezed for code generation:
flutter pub run build_runner build --delete-conflicting-outputs- hooks_riverpod: State management and dependency injection
- flutter_hooks: React-like hooks for Flutter
- go_router: Declarative routing
- formz: Form validation
- freezed: Code generation for data classes
- equatable: Value equality
- google_sign_in: Google authentication
- sign_in_with_apple: Apple authentication
- flutter_facebook_auth: Facebook authentication
- twitter_login: Twitter authentication
- auth0_flutter: Auth0 integration
- flutter_appauth: OAuth 2.0 and OpenID Connect (used by MSAL flow)
- local_auth: Biometric authentication
- base32 / crypto: TOTP secret generation and code verification
- flutter_secure_storage: Secure key-value storage (TOTP secrets stored here)
- shared_preferences: Simple key-value storage
- google_fonts: Google Fonts integration
- pinput: PIN input widget
- gap: Spacing widgets
- flutter_local_notifications: Local notifications
- build_runner: Code generation
- freezed: Immutable data classes
- very_good_analysis: Strict lint rules
Verify that Flutter is installed correctly and in your PATH:
flutter doctorEnsure you have created the config-keys.json file in the root directory as described in the configuration section.
- Verify your Google Client IDs are correct
- Check SHA-1 fingerprint is registered in Firebase Console
- Ensure GoogleService files are properly configured
- Verify Sign in with Apple capability is enabled in Xcode
- Check Bundle Identifier matches Apple Developer Portal
- Ensure redirect URI is correctly configured
- Verify Facebook App ID and Client Token
- Check Facebook app is not in Development Mode (or test users are added)
- Ensure iOS Info.plist and Android strings.xml are properly configured
- Verify all Azure configuration values are correct
- Check user flow is properly configured
- Ensure redirect URI matches your configuration
- Verify
MSAL_TENANT_IDandMSAL_CLIENT_IDmatch the Azure AD app registration - Confirm redirect URI
<MSAL_REDIRECT_SCHEME>://auth/is registered in Azure AD - Check the app has
openid,profile,email, andoffline_accesspermissions
- Ensure device clock is synchronized (TOTP is time-based)
- The app accepts codes from ±30 seconds window (one step before and after)
- If using simple TOTP after reinstalling the app, the previous secret is lost — set up again
Regenerate localization files:
flutter gen-l10nClean and rebuild:
flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputsClean and rebuild:
flutter clean
cd ios
pod install
cd ..
flutter build iosClean project:
flutter clean
cd android
./gradlew clean
cd ..
flutter build apk- Create a branch from
main - Make your changes
- Run analysis:
flutter analyze - Format code:
flutter format . - Create a Pull Request to
main
- Never commit
config-keys.jsonto version control - Use environment-specific configurations for different builds
- Implement proper token refresh mechanisms
- Use secure storage for sensitive data (
flutter_secure_storagefor TOTP secrets) - Follow OAuth 2.0 best practices
- Implement certificate pinning for production apps
[Include license information here]