AuthKit

AuthKit is a Flutter plugin for third-party authentication with a clean Dart API and provider SDKs hidden behind one facade.

Current native implementation:

  • Apple: implemented on iOS with AuthenticationServices.
  • Google: implemented internally with google_sign_in.
  • Facebook: implemented internally with flutter_facebook_auth.
  • Custom providers: configuration and channel contract are ready for provider-specific native expansion.
  • Android: Apple is unavailable by design; Google/Facebook are available through the same AuthKit API.

Clean Architecture Flow

Flutter host app
  -> AuthKit facade
    -> Use cases
      -> AuthRepository interface
        -> MethodChannelAuthRepository
          -> Apple/custom: AuthKitPlatformDataSource -> Flutter MethodChannel -> native code
          -> Google: google_sign_in adapter
          -> Facebook: flutter_facebook_auth adapter

Package structure:

lib/
  auth_kit.dart                         Public API exports and facade
  auth_kit_platform_interface.dart      Plugin platform contract
  auth_kit_method_channel.dart          MethodChannel adapter
  src/
    core/                               Provider enums, scopes, exceptions
    domain/
      entities/                         Auth config, user, credential, result
      repositories/                     AuthRepository abstraction
      usecases/                         Configure and authenticate use cases
    data/
      datasources/                      Platform data source
      repositories/                     AuthKit repository and provider adapters

Flutter Host App

Add the package:

dependencies:
  auth_kit:
    path: ../auth_kit

Configure providers before sign-in:

import 'package:auth_kit/auth_kit.dart';

final authKit = AuthKit();

await authKit.configure(
  const AuthKitConfiguration(
    providers: {
      AuthProvider.apple: ProviderAuthConfiguration.apple(),
      AuthProvider.google: ProviderAuthConfiguration.google(
        clientId: 'GOOGLE_IOS_OR_ANDROID_CLIENT_ID',
        serverClientId: 'GOOGLE_WEB_SERVER_CLIENT_ID',
      ),
      AuthProvider.facebook: ProviderAuthConfiguration.facebook(
        clientId: 'FACEBOOK_APP_ID',
      ),
    },
  ),
);

final result = await authKit.signInWithApple();
print(result.user.id);
print(result.credential.identityToken);

The host Flutter app imports only package:auth_kit/auth_kit.dart. It does not need to import google_sign_in or flutter_facebook_auth directly.

Handle errors:

try {
  final result = await authKit.signIn(AuthProvider.apple);
} on AuthKitException catch (error) {
  print('${error.code}: ${error.message}');
}

Useful error codes:

  • cancelled: user cancelled Apple sign-in.
  • provider_unavailable: provider does not run on this platform.
  • missing_configuration: sign-in was requested before that provider was configured.
  • invalid_configuration: host app passed malformed config.

iOS Host App

Minimum iOS version: 13.0.

For Apple sign-in:

  1. Open the iOS host app in Xcode.
  2. Select the app target.
  3. Add the Sign In with Apple capability.
  4. Make sure the app bundle identifier is enabled for Sign in with Apple in the Apple Developer portal.
  5. Call ProviderAuthConfiguration.apple() from Flutter before signInWithApple().

The plugin returns:

  • AuthUser.id: Apple stable user identifier.
  • AuthUser.email: email when Apple provides it.
  • AuthUser.displayName, givenName, familyName: available on the first successful authorization.
  • AuthCredential.authorizationCode: code for backend token exchange.
  • AuthCredential.identityToken: JWT identity token.

For Google/Facebook on iOS:

  1. Do not import the Google/Facebook Flutter packages in the host app.
  2. Add required URL schemes and provider metadata in Info.plist.
  3. Configure Google client IDs and Facebook app IDs in the provider consoles.
  4. Pass provider IDs through AuthKitConfiguration.

Android Host App

Minimum Android SDK: 24.

For Google/Facebook on Android:

  1. Do not import the Google/Facebook Flutter packages in the host app.
  2. Configure app IDs, client IDs, redirect schemes, and SHA fingerprints in the provider console.
  3. Add required Android manifest metadata for Facebook and Google services configuration as required by those provider SDKs.
  4. Pass the same IDs through AuthKitConfiguration from Flutter.

Apple sign-in intentionally returns provider_unavailable on Android.

Provider Config Reference

const ProviderAuthConfiguration.google(
  clientId: 'platform-client-id',
  serverClientId: 'backend-web-client-id',
  redirectUri: 'com.example.app:/oauth2redirect/google',
);

const ProviderAuthConfiguration.facebook(
  clientId: 'facebook-app-id',
  redirectUri: 'fbFACEBOOK_APP_ID://authorize',
);

const ProviderAuthConfiguration(
  clientId: 'custom-client-id',
  customProviderId: 'line',
  redirectUri: 'com.example.app:/oauth2redirect/line',
  extra: {'tenant': 'production'},
);

Use authorizationCode or identityToken on your backend to create an application session. Do not trust client-only profile data as proof of identity.