masamune_auth_apple 3.0.29 copy "masamune_auth_apple: ^3.0.29" to clipboard
masamune_auth_apple: ^3.0.29 copied to clipboard

unlisted

Authentication plugin for Masamune that can implement Apple sign-in, works only on IOS.

Masamune logo

Masamune Auth Apple

Follow on GitHub Follow on X Follow on YouTube Maintained with Melos

GitHub Sponsor


[GitHub] | [YouTube] | [Packages] | [X] | [LinkedIn] | [mathru.net]


Masamune Auth Apple #

Usage #

masamune_auth_apple adds Apple Sign In support on top of the Masamune/Katana authentication stack. It is intended to be used together with:

  • katana_auth – core authentication abstractions
  • katana_auth_firebase – optional Firebase Authentication integration
  • masamune_auth_apple_firebase – optional helper for exchanging Apple credentials with Firebase

Installation #

Install the base packages first:

flutter pub add katana_auth
flutter pub add katana_auth_firebase

Then add the Apple-specific packages:

flutter pub add masamune_auth_apple
flutter pub add masamune_auth_apple_firebase

Register Adapters #

Place the adapters near the root of your app so they are available to the authentication controller.

// lib/adapter.dart

/// Masamune adapters used in the application.
final masamuneAdapters = <MasamuneAdapter>[
  const UniversalMasamuneAdapter(),

  /// Apple Sign In adapters
  const AppleAuthMasamuneAdapter(),
  FirebaseAppleAuthMasamuneAdapter(
    functionsAdapter: const FunctionsMasamuneAdapter(),
  ),
];

Note: This package requires katana_auth and katana_auth_firebase to be installed separately. Those packages provide the core authentication infrastructure (AuthAdapter, FirebaseAuthAdapter).

AppleAuthMasamuneAdapter prepares the native Apple sign-in flow on iOS. FirebaseAppleAuthMasamuneAdapter exchanges the Apple credential for a Firebase token (via Cloud Functions or the Firebase SDK).

Authenticate with Apple #

Use Authentication from katana_auth to manage sign-in state.

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: [
            // Show user info if signed in
            if (auth.isSignedIn)
              Column(
                children: [
                  Text("Welcome!"),
                  Text("User ID: ${auth.userId}"),
                  Text("Email: ${auth.userEmail ?? 'N/A'}"),
                ],
              )
            else
              ElevatedButton.icon(
                icon: Icon(Icons.apple),
                label: const Text("Sign in with Apple"),
                onPressed: () async {
                  try {
                    await auth.signIn(AppleAuthQuery.signIn());
                    print("Signed in successfully!");
                  } catch (e) {
                    print("Sign in failed: $e");
                  }
                },
              ),
            
            // Sign out button
            if (auth.isSignedIn)
              TextButton(
                onPressed: () async {
                  await auth.signOut();
                },
                child: const Text("Sign Out"),
              ),
          ],
        ),
      ),
    );
  }
}

State Management: The Authentication controller is a ChangeNotifier, so the UI automatically rebuilds when sign-in state changes.

Handling Tokens and Linking #

  • When katana_auth_firebase is installed, Apple credentials are automatically linked to the Firebase user.
  • Link additional providers later with auth.link(AppleAuthQuery.link()) if your application allows multiple sign-in methods.
  • For anonymous user upgrade: auth.link(AppleAuthQuery.link()) preserves existing user data.

iOS Configuration #

Apple Sign In requires platform-specific configuration:

  • Enable Sign In with Apple in the Apple Developer portal and create the necessary identifiers.
  • Update Info.plist with the NSAppleMusicUsageDescription and CFBundleURLSchemes entries generated by Xcode.
  • Ensure your bundle ID matches the identifier configured in the Apple Developer console.

Tips #

  • Test on real iOS devices; the simulator may not fully support Apple Sign In flows.
  • Use AuthLoggerAdapter to capture sign-in analytics or error reports.
  • Provide fallbacks or alternative sign-in methods for platforms where Apple Sign In is unavailable.
  • Combine with masamune_purchase or other Masamune modules to unlock premium features once the user signs in.

GitHub Sponsors #

Sponsors are always welcome. Thank you for your support!

https://github.com/sponsors/mathrunet

0
likes
0
points
2.19k
downloads

Publisher

verified publishermathru.net

Weekly Downloads

Authentication plugin for Masamune that can implement Apple sign-in, works only on IOS.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, katana, masamune, sign_in_with_apple

More

Packages that depend on masamune_auth_apple