Sign In with Apple on Android and iOS using Firebase Auth

Tue, Jun 24, 2025

Read in 3 minutes

In today's multi-platform world, offering a seamless authentication experience across both Android and iOS is crucial. Apple's "Sign In with Apple" provides a privacy-focused authentication option that's now required for apps that offer other third-party sign-in methods. In this article, we'll break down a Flutter implementation that works on both platforms using Firebase Authentication.

Prerequisites

Before implementing this solution, ensure you have:

  1. Firebase project set up with Apple as a sign-in provider
  2. firebase_auth package added to your Flutter project
  3. For iOS: sign_in_with_apple package
  4. Proper configuration in your Apple Developer account
  5. Services ID configured for both platforms

Platform-Specific Considerations

The implementation differs between Android and iOS due to platform-specific requirements and available packages. Here’s why we need different approaches:

Code Breakdown

Let’s examine the signInWithApple() function in detail:

1. Function Declaration

Future<User?> signInWithApple() async {

This asynchronous function returns a Future that resolves to a Firebase User object on success or null on failure.

2. Android Implementation

if (Platform.isAndroid) {
  final appleProvider = AppleAuthProvider()
    ..addScope('email')
    ..addScope('name');

  userCredential = await FirebaseAuth.instance.signInWithProvider(
    appleProvider,
  );
}

For Android:

3. iOS Implementation

else {
  final credential = await SignInWithApple.getAppleIDCredential(
    scopes: [
      AppleIDAuthorizationScopes.email,
      AppleIDAuthorizationScopes.fullName,
    ],
  );

  final OAuthProvider oAuthProvider = OAuthProvider('apple.com');
  final credentialFirebase = oAuthProvider.credential(
    idToken: credential.identityToken,
    accessToken: credential.authorizationCode,
  );

  userCredential = await _auth.signInWithCredential(credentialFirebase);
}

For iOS:

  1. We use the sign_in_with_apple package to get Apple credentials
  2. Request the same scopes (email and full name)
  3. Create a Firebase-compatible OAuth credential
  4. Sign in to Firebase with the converted credential

4. Error Handling

} on FirebaseAuthException catch (e) {
  // Your error handling logic
} catch (e) {
  // Your error handling logic
}

Proper error handling is crucial for:

Platform-Specific Setup

iOS Configuration

  1. Enable Sign In with Apple in your Xcode project capabilities
  2. Configure your Sign In with Apple service in Apple Developer portal
  3. Add the Associated Domains entitlement
  4. Set up your Services ID with the correct return URLs

Android Configuration

  1. Enable Sign In with Apple in Firebase Console
  2. Configure your SHA-256 certificate fingerprint in Firebase
  3. Set up the OAuth redirect URI in your Apple Developer account

Important Considerations

  1. User Data: Apple only provides the user’s name and email on the first login
  2. Nonce Handling: For enhanced security, consider implementing nonce verification
  3. Testing: Always test with real devices as simulators may behave differently
  4. App Review: Apple requires Sign In with Apple for apps that use third-party login

Best Practices

  1. UI Consistency: Follow Apple’s Human Interface Guidelines for the sign-in button
  2. Error Recovery: Provide clear instructions when errors occur
  3. User State: Handle cases where users revoke Apple ID permissions
  4. Data Migration: Plan for scenarios where users switch authentication methods

Troubleshooting Common Issues

  1. Missing Email: Implement a fallback if email isn’t provided
  2. Scope Limitations: Remember you can’t request additional scopes later
  3. Firebase Configuration: Double-check your Firebase Apple provider settings
  4. Certificate Issues: Ensure your signing certificates are up to date

Conclusion

Implementing Sign In with Apple across platforms requires understanding both the platform-specific requirements and Firebase’s authentication system. The provided code offers a clean, maintainable approach that handles both platforms appropriately while maintaining consistency in your authentication flow.

Remember to always test thoroughly on both platforms and handle edge cases gracefully. With this implementation, you’ll provide users with a secure, privacy-focused authentication option that meets Apple’s guidelines while leveraging Firebase’s powerful authentication system.


Shohruh AK





See Also

Getx | obs - not updating data in Controller properly | Flutter
New App Signing feature provided by Google Play
4 Ways to Close Keyboard in Flutter App
Build Flutter Calculator App - Tutorial for Beginners
Save any file in external storage in Flutter app: Full Guide