Authentication Fire Social
Features
⚠️ WARNING ⚠️
First of all, you should make sure that the Firebase project is already configured and you have access to it.
Necessary Dependencies
Add the following dependencies to your pubspec.yaml file:
firebase_auth: ^4.4.2 # Or higher
firebase_core: ^2.3.0 # Or higher
flutter_gb_authentication_fire_social: 2.0.0
Depending on which social provider used install the required companion package
flutter_gb_authentication_fire_social_google
flutter_gb_authentication_fire_social_apple
flutter_gb_authentication_fire_social_facebook
Android Configuration
- 
Go to the Firebase Console and then open the project configuration. 
- 
Scroll down until Your apps section, you will see the configured applications. 
- 
Click the google-services.json button to download the configuration file in both Android apps (Dev and Production). 
- 
Now in your project folder, go to the android/app/src/folder.
- 
Create a folder for each flavor inside the mentioned folder above and paste the corresponding google-services.jsonfile for each one.
- 
After that, in the android/build.gradlefile, add the Google Services plugin within dependencies.
dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'  // Google Services plugin
    }
- In the android/app/build.gradlefile, apply the Google Services plugin.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'  // Google Services plugin
- We need to implement Multidex support in our Gradle dependencies inside the android/app/build.gradlefile to prevent any issues while using Firebase.
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:2.0.1' // MultiDex
}
- Also, we will need to enable the Multidex support within the mentioned file above but inside of defaultConfig.
defaultConfig {
        applicationId "com.example.app"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true // Enable MultiDex
    }
- 
Google - Google Config
- Make sure you add your key SHA to firebase project configuration.
 
 
- Google Config
- 
Facebook - 
Facebook Config - If your project handles login-signup with Facebook, you should add your facebook_app_idandfacebook_client_tokenwithinandroid/app/src/main/res/values/strings.xmlfile.
 <resources> <string name="facebook_app_id">YOUR_ID</string> <string name="facebook_client_token">YOUR_CLIENT_TOKEN</string> </resources>- 
You will need to add a query and meta-data tag within android/src/app/main/AndroidManifest.xmlfile to finish the FaceBook configuration.<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.boxxie.app"> <!-- If using Facebook ADD THIS queries --> <queries> <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> </queries> <application android:label="@string/app_name" android:name="${applicationName}" android:icon="@mipmap/launcher_icon"> <!-- If using Facebook ADD BOTH meta-data --> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" /> <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token" /> ...More code </application> ...More code </manifest>
 
- If your project handles login-signup with Facebook, you should add your 
 
- 
- 
Apple Sign In - Apple Config
- Activate Apple Sign-In method under Firebase Console → Authentication → Sign In method
- We recommend following these instructions to configure Apple Services to create an Apple Sign-in service ID
- Create Apple Sign-in service
- Enable Apple Sign-in capability on each App ID
- Generate a Key for the Apple Sign in Service
- Fill Firebase configuration data in Apple Sign-in method
 
- Configure AuthenticationFireSocialConfigModel.appleWebAuthentication (WebAuthenticationOptions)setting.
 
 
- Apple Config
iOS Configuration
- 
Go to the Firebase Console and then open the project configuration. 
- 
Scroll down until Your apps section, you will see the configured applications. 
- 
Click the GoogleService-Info.plist button to download the configuration file in both iOS apps (Dev and Production). 
- 
Now in your project folder, go to the iosfolder and create a new one calledconfig, in case it doesn’t exists.
- 
Within configfolder create a folder for each scheme and paste the correspondingGoogleService-Info.plistfile for each one.
- 
Make sure you follow this instructions if using a flavored project. 
- 
Open your ios/Runner/Info.plistfile and add the following code.
<key>CFBundleURLTypes</key>
<array>
		<dict>
				<key>CFBundleTypeRole</key>
				<string>Editor</string>
				<key>CFBundleURLSchemes</key>
				<array>
					<!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
					<string>$(GOOGLE_REVERSED_ID)</string>
				</array>
		</dict>
</array>
- For Facebook:
- 
Add in you ios/Runner/Info.plist:<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb{FACEBOOK_CLIENT_ID}</string> </array> </dict> </array> <key>FacebookAppID</key> <string>{FACEBOOK_CLIENT_ID}</string> <key>FacebookClientToken</key> <string>{FACEBOOK_CLIENT_TOKEN}</string> <key>FacebookDisplayName</key> <string>{App Name}</string> <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fb-messenger-share-api</string> <string>tel</string> <string>https</string> <string>http</string> </array>
 
- 
- For Apple:
- Enable Apple Sign-In capability inside the XCode project.
 
Injection Configuration
- In your lib/core/injection_config.dartfile you should create an instance ofAuthenticationFireSocialConfigModeland add your custom endpoints, do it withinconfigureDependenciesmethod.
final authConfig = AuthenticationFireSocialConfigModel(
    loginCredentialsAPIendpoint: () {
      return EnvironmentConfig.api_url + ApiEndpoints.login();
    },
    customLoginRequestMapper: (email, password) {
      return {
        "emailOrUsername": email,
        "password": password,
      };
    },
    signupCredentialsAPIendpoint: () {
      return EnvironmentConfig.api_url + ApiEndpoints.signup();
    },
    authenticateGoogleAPIendpoint: (_) {
      return EnvironmentConfig.api_url + ApiEndpoints.authFirebaseSocial();
    },
    authenticateFacebookAPIendpoint: (_) {
      return EnvironmentConfig.api_url + ApiEndpoints.authFirebaseSocial();
    },
    authenticateAppleAPIendpoint: (_) {
      return EnvironmentConfig.api_url + ApiEndpoints.authFirebaseSocial();
    },
);
- Also you will need call configureAuthenticationAdvancedInjectioninside ofconfigureDependenciesmethod.
// configure Auth Package
  await configureAuthenticationAdvancedInjection(
    environment,
    authConfig,
    customAuthServiceFactory: (() {
      // register custom impl of auth Service
      return CustomAuthenticationServiceImpl(
        config: authConfig,
        httpClient: getIt(),
        sharedPreferences: getIt(),
        appleSignInFacade: getIt(),
        facebookSignInFacade: getIt(),
        googleSignInFacade: getIt(),
        logger: getAuthenticationSocialLogger(authConfig),
      );
    }),
  );
Firebase Initialization
Make sure you initialize Firebase at the beginning of your application, normally main.dart.
Libraries
- application/application
- application/bloc/bloc
- config/config
- configure_injection
- domain/domain
- domain/entities/entities
- domain/services/services
- infrastructure/facades/anonymous_facade
- infrastructure/facades/apple_sign_in_facade
- infrastructure/facades/facades
- infrastructure/facades/facebook_sign_in_facade
- infrastructure/facades/google_sign_in_facade
- infrastructure/infrastructure
- infrastructure/models/models
- infrastructure/services/services
- mocks/mocks
- mocks/mocks.mocks
- presentation/containers/advanced_bloc_builder
- presentation/containers/advanced_bloc_listener
- presentation/containers/authentication_advanced_provider_container
- presentation/containers/containers
- presentation/presentation
- utils/logger
- utils/types/auth_method
- utils/types/types
- utils/utils