oauth_connection
A Flutter package for simplified, BLoC-powered OAuth authentication. This package provides a unified way to integrate Google, Facebook, Instagram, and Apple Sign-In with a clean, controller-based initialization and ready-to-use UI components.
Features
- Controller-Based Initialization: Configuration is decoupled from the UI, allowing you to initialize providers dynamically via dedicated controllers.
- Native Apple Sign-In: Fully integrated for iOS and Android, supporting the latest App Store requirements.
- Plug-and-Play Buttons: Pre-built, brand-compliant buttons that handle the entire OAuth flow internally.
- Unified Listeners: Consistent success and failure callbacks across all social providers.
- State Management: Built-in BLoC integration to handle authentication states seamlessly.
Getting started
Add the dependency to your pubspec.yaml:
dependencies:
oauth_connection: ^1.1.0
Platform Requirements
- iOS: Requires iOS 13.0 or higher. Ensure the "Sign In with Apple" capability is added in Xcode.
- Android: Requires minSdkVersion 21 or higher.
The Core Idea
The package operates on a simple Initialize -> Render -> Listen workflow.
1. Initialize via Controllers
You don't need to pass configuration data directly to the UI. Instead, use the static init methods on the controllers (e.g., GoogleAuthController, AppleAuthController, etc.) to inject your backend endpoints, client IDs, and debugging preferences.
2. Drop in the Button
Once a controller is initialized, simply export and use the corresponding button from the package. These buttons are self-contained and manage their own authentication logic.
3. Boom! Implement Listeners
Every button provides standardized listeners. Just implement onSuccess to receive the access token and onFailure to handle errors with localized messages.
// Example of the "Plug and Play" buttons
AppleSignInButton(
onSuccess: (state) => handleMySuccess(state.accessToken),
onFailure: (state) => handleMyError(state.translatedMessage),
),
GoogleSignInButton(
onSuccess: (state) => handleMySuccess(state.accessToken),
onFailure: (state) => handleMyError(state.translatedMessage),
),
Localization
The package includes built-in translations for the button labels. To support Apple Sign-In in Arabic, ensure your localization keys are mapped as follows:
"apple": {
"signIn": "تسجيل الدخول باستخدام أبل",
"signUp": "إنشاء حساب باستخدام أبل"
}