Laravel Socialite-style social authentication for the Magic Framework.
Config-driven OAuth with extensible drivers for Google, Microsoft, GitHub, and beyond.
Website Β· Docs Β· pub.dev Β· Issues Β· Discussions
Alpha β
magic_social_authis under active development. APIs may change between minor versions until1.0.0.
Adding social login to a Flutter app means juggling platform-specific SDKs, OAuth redirect flows, token exchange with your backend, and wiring it all together differently for each provider. Every project reinvents the same boilerplate.
Magic Social Auth gives you a Socialite-style facade. One config file declares your providers. One line authenticates. Drivers handle platform differences. A pluggable handler chain sends tokens to your backend.
Config-driven social auth. Define your providers, credentials, and scopes once. Magic Social Auth handles the rest.
| Feature | Description | |
|---|---|---|
| π | Socialite-Style API | SocialAuth.driver('google').authenticate() β familiar, expressive |
| π₯ | Built-in Drivers | Google (native SDK), Microsoft (OAuth), GitHub (OAuth) out of the box |
| π | Extensible Drivers | Add any provider via manager.extend('apple', factory) |
| π | Custom Auth Handlers | Swap the default HTTP handler for Firebase, Supabase, or anything else |
| π± | Platform Detection | Drivers declare supported platforms β check with SocialAuth.supports() |
| π¨ | Config-Driven UI | SocialAuthButtons widget renders enabled providers with icons automatically |
| πͺ | Sign-Out Support | SocialAuth.signOut() clears cached sessions across all providers |
| π¦ | Service Provider | Two-phase bootstrap via Magic's IoC container β zero manual wiring |
dependencies:
magic_social_auth: ^0.0.1-alpha.1// lib/config/app.dart
import 'package:magic_social_auth/magic_social_auth.dart';
Map<String, dynamic> get appConfig => {
'app': {
'providers': [
// ... other providers
(app) => SocialAuthServiceProvider(app),
],
},
};// lib/config/social_auth.dart
import 'package:magic/magic.dart';
Map<String, dynamic> get socialAuthConfig => {
'social_auth': {
'endpoint': '/auth/social/{provider}',
'providers': {
'google': {
'enabled': true,
'client_id': env('GOOGLE_CLIENT_ID'),
'server_client_id': env('GOOGLE_SERVER_CLIENT_ID'),
'scopes': ['email', 'profile'],
},
'microsoft': {
'enabled': true,
'client_id': env('MICROSOFT_CLIENT_ID'),
'tenant': env('MICROSOFT_TENANT', 'common'),
'callback_scheme': 'myapp',
'scopes': ['openid', 'profile', 'email'],
},
'github': {
'enabled': true,
'client_id': env('GITHUB_CLIENT_ID'),
'callback_scheme': 'myapp',
'scopes': ['read:user', 'user:email'],
},
},
},
};// lib/main.dart
import 'config/social_auth.dart';
await Magic.init(
configFactories: [
() => appConfig,
() => socialAuthConfig, // Add this
],
);await SocialAuth.driver('google').authenticate();That's it β the default HttpSocialAuthHandler sends the token to your Laravel backend and logs the user in via Sanctum.
The config file at lib/config/social_auth.dart controls everything:
Map<String, dynamic> get socialAuthConfig => {
'social_auth': {
// Backend endpoint for token exchange
'endpoint': '/auth/social/{provider}',
'providers': {
'google': {
'enabled': true,
'client_id': env('GOOGLE_CLIENT_ID'),
'server_client_id': env('GOOGLE_SERVER_CLIENT_ID'),
'scopes': ['email', 'profile'],
},
'microsoft': {
'enabled': true,
'client_id': env('MICROSOFT_CLIENT_ID'),
'tenant': env('MICROSOFT_TENANT', 'common'),
'callback_scheme': 'myapp',
'scopes': ['openid', 'profile', 'email'],
},
'github': {
'enabled': true,
'client_id': env('GITHUB_CLIENT_ID'),
'callback_scheme': 'myapp',
'scopes': ['read:user', 'user:email'],
},
},
},
};All values are read at runtime via ConfigRepository. Provider-specific OAuth setup (Google Cloud Console, Azure Portal, GitHub Developer Settings) is covered in the configuration docs.
await SocialAuth.driver('google').authenticate();
await SocialAuth.driver('microsoft').authenticate();
await SocialAuth.driver('github').authenticate();if (SocialAuth.supports('google')) {
// Show Google sign-in button
}// Register in your ServiceProvider.boot()
SocialAuth.manager.extend('apple', (config) => AppleDriver(config));
// Use it
await SocialAuth.driver('apple').authenticate();Replace the default HTTP handler with your own logic:
class FirebaseAuthHandler implements SocialAuthHandler {
@override
Future<void> handle(SocialToken token) async {
final credential = GoogleAuthProvider.credential(
idToken: token.idToken,
accessToken: token.accessToken,
);
await FirebaseAuth.instance.signInWithCredential(credential);
}
}
// Register it
SocialAuth.manager.setHandler(FirebaseAuthHandler());Config-driven UI that renders buttons for all enabled, platform-supported providers:
SocialAuthButtons(
onAuthenticate: (provider) async {
await SocialAuth.driver(provider).authenticate();
},
loadingProvider: currentlyLoading, // shows spinner on active button
mode: SocialAuthMode.signIn, // or SocialAuthMode.signUp
)Register UI metadata for custom providers:
SocialAuth.manager.registerProviderDefaults('apple', SocialProviderDefaults(
label: 'Apple',
iconSvg: '<svg>...</svg>',
order: 4,
));await SocialAuth.signOut(); // Clears cached sessions across all providersApp launch β SocialAuthServiceProvider.register()
β binds SocialAuthManager singleton via IoC
β SocialAuth facade resolves manager from container
β SocialAuth.driver('google') β manager.driver('google')
β reads config via ConfigRepository
β resolves built-in or custom driver
β driver.authenticate()
β driver.getToken() (native SDK / OAuth browser)
β manager.handleAuth(token) β handler.handle(token)
β default handler POSTs to backend β Auth.login()
Key patterns:
| Pattern | Implementation |
|---|---|
| Singleton Manager | SocialAuthManager β central orchestrator |
| Strategy (Driver) | GoogleDriver, MicrosoftDriver, GithubDriver implement SocialDriver |
| Handler Chain | SocialAuthHandler β swap HTTP for Firebase, Supabase, etc. |
| Service Provider | Two-phase bootstrap: register() (sync) β boot() (async) |
| IoC Container | Binding via app.singleton() / Magic.make() |
| Static Facade | SocialAuth β zero-instance access to the manager |
| Document | Description |
|---|---|
| Installation | Adding the package and registering the provider |
| Configuration | Config reference, OAuth setup for Google/Microsoft/GitHub |
| Drivers | Built-in drivers and writing custom ones |
| Handlers | Default HTTP handler and custom handler implementations |
| Architecture | Manager, facade, driver, and handler patterns |
Contributions are welcome! Please see the issues page for open tasks or to report bugs.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Write tests following the TDD flow β red, green, refactor
- Ensure all checks pass:
flutter test,dart analyze,dart format . - Submit a pull request
Magic Social Auth is open-sourced software licensed under the MIT License.
Built with care by FlutterSDK
If Magic Social Auth helps your project, consider giving it a star on GitHub.