masamune_auth_facebook 3.1.6
masamune_auth_facebook: ^3.1.6 copied to clipboard
Authentication plugin for Masamune that can implement Facebook(Meta) sign-in.
Masamune Auth Facebook
[GitHub] | [YouTube] | [Packages] | [X] | [LinkedIn] | [mathru.net]
Masamune Auth Facebook #
Usage #
masamune_auth_facebook integrates Facebook login with the Masamune/Katana authentication stack. It is intended to work alongside:
katana_auth– core authentication abstractionskatana_auth_firebase– optional Firebase Authentication integration
Installation #
Install the base packages first:
flutter pub add katana_auth
flutter pub add katana_auth_firebase
Then add Facebook support:
flutter pub add masamune_auth_facebook
If you need to link Facebook with Firebase, also install:
flutter pub add masamune_auth_facebook_firebase
Register Adapters #
Configure adapters near the root of your application so the Facebook SDK can authenticate properly.
// lib/adapter.dart
/// Masamune adapters used in the application.
final masamuneAdapters = <MasamuneAdapter>[
const UniversalMasamuneAdapter(),
const FacebookAuthMasamuneAdapter(
clientToken: "YOUR_FACEBOOK_APP_ID",
clientSecret: "YOUR_FACEBOOK_APP_SECRET",
),
];
Note: This package requires katana_auth and katana_auth_firebase to be installed separately. Those packages provide the core authentication infrastructure.
FacebookAuthMasamuneAdapter handles the native login flow and provides access tokens to the Katana authentication layer.
Authenticate Users #
Use Authentication from katana_auth to initiate the Facebook sign-in flow.
class SignInPage extends PageScopedWidget {
@override
Widget build(BuildContext context, PageRef ref) {
final auth = ref.app.controller(Authentication.query());
// Initialize on page load
ref.page.on(
initOrUpdate: () {
auth.initialize();
},
);
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (auth.isSignedIn)
Column(
children: [
Text("Welcome!"),
Text("User ID: ${auth.userId}"),
Text("Email: ${auth.userEmail ?? 'N/A'}"),
TextButton(
onPressed: () => auth.signOut(),
child: const Text("Sign Out"),
),
],
)
else
ElevatedButton.icon(
icon: Icon(Icons.facebook),
label: const Text("Sign in with Facebook"),
onPressed: () async {
try {
await auth.signIn(FacebookAuthQuery.signIn());
} catch (e) {
print("Sign in failed: $e");
}
},
),
],
),
),
);
}
}
The controller automatically notifies listeners on state changes.
Firebase Integration #
If you also include masamune_auth_facebook_firebase, add the Firebase adapter and ensure you exchange Facebook credentials for Firebase tokens on the server (via Cloud Functions) or directly with the Firebase SDK.
FirebaseFacebookAuthMasamuneAdapter(
functionsAdapter: const FunctionsMasamuneAdapter(),
),
Facebook Platform Setup #
- Create a Facebook app and obtain the App ID and App Secret.
- Configure redirect URIs, bundle IDs, and package names in Facebook Developer settings.
- Update your iOS and Android projects with the required meta-data (e.g.,
AndroidManifest.xml,Info.plist).
Tips #
- Test on real devices; browsers and simulators may have limitations when invoking the Facebook app or WebView.
- Provide fallbacks or alternative sign-in options for regions where Facebook is unavailable.
- Monitor token expiration and refresh logic if your app relies on long-lived sessions.
- Pair with
AuthLoggerAdapterto capture login analytics.
GitHub Sponsors #
Sponsors are always welcome. Thank you for your support!