Skip to content
Back to archipelago.banuacoder.com

Feature SDKs

How to add Google, Apple and Facebook sign-in to a Flutter app ​

Pro Reference for social_auth_sdk: every variable, option and package it generates. Command: archipelago generate social_auth_sdk

Generate the Social Auth SDK with per-provider flags, configure each provider, and meet the App Store rule for Sign in with Apple.

What you'll learn ​

  • Generating the Social Auth SDK with per-provider feature flags
  • Understanding the generated package structure and DI wiring order
  • Configuring Google Sign-In, Sign in with Apple, and Facebook Login
  • Apple's App Store requirement for Sign in with Apple

Prerequisites ​

The brick generates monitoring_sdk and auth_sdk for you if they are missing. The orchestrator calls AuthSDK.loginSuccess and reports to AppMonitoring.

Step 1: Generate the Social Auth SDK ​

bash
archipelago generate social_auth_sdk

The prompts are:

  • includeGoogle: Google Sign-In (default true)
  • includeApple: Sign in with Apple (default true)
  • includeFacebook: Facebook Login (default false)

Generation stops if all three are false.

App Store policy

Apple requires Sign in with Apple whenever your app offers any other third-party login. If you set includeApple: false while enabling Google or Facebook, the generator prints a warning. It does not stop. App Store review can reject your app unless you add Sign in with Apple before you submit.

Or use a config file:

json
{
  "includeGoogle": true,
  "includeApple": true,
  "includeFacebook": false
}
bash
archipelago generate social_auth_sdk --config social_auth_config.json

Step 2: Understand the Generated Structure ​

The brick generates one package per enabled provider plus a shared API contract and an orchestrator impl:

text
features/social_auth/
├── social_auth_api/
│   └── lib/src/
│       └── social_auth_sdk.dart              # Shared contract
├── social_auth_impl/
│   └── lib/src/
│       └── social_auth_impl.dart             # Orchestrator (wires providers)
├── google_social_auth_impl/                  # includeGoogle=true
│   └── lib/src/
│       └── google_social_auth_impl.dart
├── apple_social_auth_impl/                   # includeApple=true
│   └── lib/src/
│       └── apple_social_auth_impl.dart
└── facebook_social_auth_impl/                # includeFacebook=true (if enabled)
    └── lib/src/
        └── facebook_social_auth_impl.dart

Step 3: Check the Registration ​

The post-generation hook wires the DI for you. You write no registration code.

  1. Each enabled provider module registers first. Each handler is @Named with google, apple or facebook, so providers coexist.
  2. SocialAuthImplGlobalModule registers last. It registers SocialAuthSDK as a lazy singleton. The handler list is read the first time something resolves the SDK.
  3. Nothing runs at boot. Each handler starts its vendor SDK on its first sign-in.
  4. A provider you turn off on a later run is removed from the injector and the app pubspec.yaml.

Step 4: Configure Google Sign-In ​

The hooks write no platform files. Follow the google_sign_in setup guide.

Android: add the OAuth 2.0 client ID as a resValue in android/app/build.gradle:

groovy
android {
  defaultConfig {
    resValue "string", "default_web_client_id", "<YOUR_CLIENT_ID>.apps.googleusercontent.com"
  }
}

iOS: add the reversed client ID to Info.plist:

xml
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>com.googleusercontent.apps.YOUR_CLIENT_ID</string>
    </array>
  </dict>
</array>

Step 5: Configure Sign in with Apple ​

Follow the sign_in_with_apple setup guide.

  1. In Xcode, enable the Sign in with Apple capability under your app's target → Signing & Capabilities.
  2. In the Apple Developer portal, configure a Services ID for web/Android redirect support (required for non-iOS platforms).
  3. No Info.plist or build.gradle changes needed, the capability alone is sufficient for iOS.

Step 6: Configure Facebook Login (optional) ​

Follow the flutter_facebook_auth setup guide.

Android: add to android/app/src/main/res/values/strings.xml:

xml
<string name="facebook_app_id">YOUR_APP_ID</string>
<string name="facebook_client_token">YOUR_CLIENT_TOKEN</string>

iOS: add to Info.plist:

xml
<key>FacebookAppID</key>
<string>YOUR_APP_ID</string>
<key>FacebookClientToken</key>
<string>YOUR_CLIENT_TOKEN</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fbYOUR_APP_ID</string>
    </array>
  </dict>
</array>

Step 7: Use the Social Auth API ​

Take SocialAuthSDK by constructor. Show a button only for providers that exist:

dart
if (socialAuth.isProviderAvailable(SocialAuthProvider.google)) {
  final result = await socialAuth.signIn(SocialAuthProvider.google);

  switch (result) {
    case SocialAuthSuccess():
      // The orchestrator already called AuthSDK.loginSuccess for you.
      break;
    case SocialAuthCancelled():
      break; // The user backed out. This is silent.
    case SocialAuthFailure(:final reason):
      break; // reason: notSupported or providerError
  }
}

await socialAuth.signOut(); // every provider, safe to repeat

availableProviders lists the providers wired into DI. A call for a provider with no handler returns SocialAuthFailure(notSupported) and does not throw. An exception in a handler goes to AppMonitoring and returns SocialAuthFailure(providerError).

Common Customizations ​

CustomizationWhere to Change
Add a provider laterRun archipelago generate social_auth_sdk again with the new flag set to true
Custom error handlingThe handler in the provider package. Errors go to AppMonitoring
Scope changes (Google)Pass scopes to GoogleSignIn() in google_social_auth_impl
Server-side token exchangeChange social_auth_sdk_impl.dart and your auth_sdk backend calls

Next Steps ​