A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs.

Overview

flutter_facebook_login

pub package Build Status Coverage Status

A Flutter plugin for using the native Facebook Login SDKs on Android and iOS.

AndroidX support

Installation

To get things up and running, you'll have to declare a pubspec dependency in your Flutter project. Also some minimal Android & iOS specific configuration must be done, otherwise your app will crash.

On your Flutter project

See the installation instructions on pub.

Android

This assumes that you've done the "Associate Your Package Name and Default Class with Your App" and "Provide the Development and Release Key Hashes for Your App" in the the Facebook Login documentation for Android site.

After you've done that, find out what your Facebook App ID is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.

Once you have the Facebook App ID figured out, you'll have to do two things.

First, copy-paste the following to your strings resource file. If you don't have one, just create it.

<your project root>/android/app/src/main/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Your App Name here.</string>

    <!-- Replace "000000000000" with your Facebook App ID here. -->
    <string name="facebook_app_id">000000000000</string>

    <!--
      Replace "000000000000" with your Facebook App ID here.
      **NOTE**: The scheme needs to start with `fb` and then your ID.
    -->
    <string name="fb_login_protocol_scheme">fb000000000000</string>
</resources>

Then you'll just have to copy-paste the following to your Android Manifest:

<your project root>/android/app/src/main/AndroidManifest.xml

<meta-data android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

<activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/fb_login_protocol_scheme" />
    </intent-filter>
</activity>

A sample of a complete AndroidManifest file can be found here.

Done!

iOS

This assumes that you've done the "Register and Configure Your App with Facebook" step in the the Facebook Login documentation for iOS site. (Note: you can skip "Step 2: Set up Your Development Environment" and "Step 5: Connect Your App Delegate").

After you've done that, find out what your Facebook App ID is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.

Once you have the Facebook App ID figured out, then you'll just have to copy-paste the following to your Info.plist file, before the ending </dict></plist> tags. (NOTE: If you are using this plugin in conjunction with for example google_sign_in plugin, which also requires you to add CFBundleURLTypes key into Info.plist file, you need to merge them together).

<your project root>/ios/Runner/Info.plist

<key>CFBundleURLTypes</key>
<array>
    <!--
    <dict>
    ... Some other CFBundleURLTypes definition.
    </dict>
    -->
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <!--
              Replace "000000000000" with your Facebook App ID here.
              **NOTE**: The scheme needs to start with `fb` and then your ID.
            -->
            <string>fb000000000000</string>
        </array>
    </dict>
</array>

<key>FacebookAppID</key>

<!-- Replace "000000000000" with your Facebook App ID here. -->
<string>000000000000</string>
<key>FacebookDisplayName</key>

<!-- Replace "YOUR_APP_NAME" with your Facebook App name. -->
<string>YOUR_APP_NAME</string>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-share-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

A sample of a complete Info.plist file can be found here.

Done!

How do I use it?

The library tries to closely match the native Android & iOS login SDK APIs where possible. For complete API documentation, just see the source code. Everything is documented there.

Since sample code is worth more than one page of documentation, here are the usual cases covered:

import 'package:flutter_facebook_login/flutter_facebook_login.dart';

final facebookLogin = FacebookLogin();
final result = await facebookLogin.logIn(['email']);

switch (result.status) {
  case FacebookLoginStatus.loggedIn:
    _sendTokenToServer(result.accessToken.token);
    _showLoggedInUI();
    break;
  case FacebookLoginStatus.cancelledByUser:
    _showCancelledMessage();
    break;
  case FacebookLoginStatus.error:
    _showErrorOnUI(result.errorMessage);
    break;
}

You can also change the visual appearance of the login dialog. For example:

// Let's force the users to login using the login dialog based on WebViews. Yay!
facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;

The complete API documentation lives with the source code, which can be found here.

Getting the Facebook profile of a signed in user

For now, this feature isn't going to be integrated into this plugin. See the discussion here.

However, you can get do this in four lines of Dart code:

final result = await facebookSignIn.logIn(['email']);
final token = result.accessToken.token;
final graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${token}');
final profile = JSON.decode(graphResponse.body);

The profile variable will now contain the following information:

{
   "name": "Iiro Krankka",
   "first_name": "Iiro",
   "last_name": "Krankka",
   "email": "iiro.krankka\u0040gmail.com",
   "id": "<user id here>"
}

Troubleshooting

If you haven't completed AndroidX setup in your Flutter project, your project might not build. The simple solution is adding 2 lines in your android/gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

For more, see "AndroidX compatibility" in the official Flutter documentation.

Comments
  • I am getting no implementation found error

    I am getting no implementation found error

    Hi Sir,

    I am getting below error when I had integrated the facebook login in my app please help me

    MissingPluginException(No implementation found for method loginWithReadPermissions on channel com.roughike/flutter_facebook_login)

      Future<Null> _login() async {
        final FacebookLoginResult result =
            await facebookSignIn.logInWithReadPermissions(['email']);
    
        switch (result.status) {
          case FacebookLoginStatus.loggedIn:
            final FacebookAccessToken accessToken = result.accessToken;
            print(accessToken.token);
            break;
          case FacebookLoginStatus.cancelledByUser:
            print('Login cancelled by the user.');
            break;
          case FacebookLoginStatus.error:
            print(result.errorMessage);
            break;
        }
      }
    
    
    opened by ntsdev 34
  • Facebook Platform - App has been restricted - Critical

    Facebook Platform - App has been restricted - Critical

    Hello, I've had this message a few times now. It's fairly critical as now no one can login on Android. They are saying the Android version is using an old SDK. I'm only using this library to login.

    Also is this the only Flutter Facebook library? Is anyone maintaining it?

    Hi,
    
    In working to create a great Platform experience for everyone, we ask developers to ensure the apps they build comply with our Platform Policies. Your app (-----) doesn't comply with the following Platform Policies:
    
    Platform Policy 8.2: Native iOS and Android apps that implement Facebook Login must use our official SDKs for Login. 
    
    Please make sure your Android app is using the most recent version of our SDK for Login. You can find more information on our Android SDK for Login and other Login-related products here: https://developers.facebook.com/docs/facebook-login/android.
    
    You can see our visual example for this policy here: https://developers.facebook.com/policy#7-2-photo.
    
    
    Since we're striving to improve the Platform experience, your app's ability to do the following has been restricted.
    
    opened by ollydixon 27
  • Facebook not login with install facebook app in flutter

    Facebook not login with install facebook app in flutter

    I had installed a Facebook login in my flutter app . and everything alright. but when install Facebook app. login square show and when press login nothing does and not log in. why?

    opened by harithany 17
  • ------ DEAD PROJECT ------

    ------ DEAD PROJECT ------

    I have no idea what happened to the original maintainer of this library @roughike, I hope he's in good health, but since there have been no bug fixes, upgrades, replies or PR accepted or denied, I think it's safe to assume that this library is dead and should be avoided from now on.

    opened by feinstein 17
  • FBSDKCoreKit cocoapods issues with latest version 3

    FBSDKCoreKit cocoapods issues with latest version 3

    After updating my Flutter project to version 3.0.0, I'm no longer able to build on iOS.

    Error:

        [!] CocoaPods could not find compatible versions for pod "FBSDKCoreKit":
          In Podfile:
            FBSDKCoreKit (= 4.39.1)
            flutter_facebook_login (from `.symlinks/plugins/flutter_facebook_login/ios`) was resolved to 0.0.1, which depends on
              FBSDKCoreKit (~> 5.5)
        Specs satisfying the `FBSDKCoreKit (= 4.39.1), FBSDKCoreKit (~> 5.5)` dependency were found, but they required a higher minimum deployment target.
    

    This is even with setting a minimum deployment target of 11.0 both in the Podfile, and in the Xcode project settings.

    flutter doctor:

    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.14.4 18E226, locale en-GB)
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    [✓] Xcode - develop for iOS and macOS (Xcode 10.2)
    [✓] Android Studio (version 3.5)
    [✓] VS Code (version 1.39.1)
    [✓] Connected device (3 available)
    
    • No issues found!
    

    pod --version is 1.8.3

    Already run pod repo update prior to building the app.

    None of this is a problem with version 2.x.

    opened by bizz84 16
  • Support AndroidX

    Support AndroidX

    When I build with flutter build apk, I’ve got following error:

    * What went wrong:
    Execution failed for task ':flutter_facebook_login:verifyReleaseResources'.
    > java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
      /Users/yuda/coin/build/flutter_facebook_login/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
      /Users/yuda/coin/build/flutter_facebook_login/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
      /Users/yuda/coin/build/flutter_facebook_login/intermediates/res/merged/release/values/values.xml:2779: error: resource android:attr/fontVariationSettings not found.
      /Users/yuda/coin/build/flutter_facebook_login/intermediates/res/merged/release/values/values.xml:2780: error: resource android:attr/ttcIndex not found.
      error: failed linking references
    

    This commit fix it

    opened by yudaprama 15
  • Bump SDK deps to 5.5.0 and remove deprecated SDK methods and usages

    Bump SDK deps to 5.5.0 and remove deprecated SDK methods and usages

    • Update Android & iOS Facebook Login dependencies to 5.5.0
    • Removed deprecated method loginWithPublishPermissions and renamed loginWithReadPermission to login
    • The behavior parameter is now ignored on iOS as it is not supported anymore by the Facebook Login SDK
    • Bump iOS deployment target to 9.0
    opened by sroddy 14
  • logInWithReadPermissions never ends

    logInWithReadPermissions never ends

    Hi there!

    I'm writing an app and am struggling to make facebook login work. I've followed all the instructions but logInWithReadPermissions method just doesn't seem to ever return (even if I log in or cancel the Facebook dialog).

    My code:

    FacebookLogin facebookLogin = new FacebookLogin();
      
      Future<String> loginWithFaceBook() async {
        return facebookLogin.logInWithReadPermissions(['email', 'public_profile'])
            .then((fbResult) {
          switch (fbResult.status) {
            case FacebookLoginStatus.loggedIn:
              return fbResult.accessToken.token;
            case FacebookLoginStatus.cancelledByUser:
              throw new StateError("Cancelled by user");
            case FacebookLoginStatus.error:
              throw new StateError(FacebookLoginStatus.error.toString());
          }
        });
      }
    

    I know this is not an actual issue but I'd really appreciate some help.

    Thank you in advance.

    opened by zigapk 11
  • Facebook SDK v9?

    Facebook SDK v9?

    I got an email from Facebook that the current SDK is no longer supported, and some of my apps have been upgraded to v9.0.

    Is support for Facebook SDK v9 planned?

    opened by vixez 10
  • Fix loginkit dependency

    Fix loginkit dependency

    Bumps the version of FBSDKLoginKit fixing a problem when solving transitive dependencies after a pod update.

    Since the version of FBSDKCoreKit is not locked, a pod update downloads the latest version (4.42.0) which introduces breaking changes for the 4.39.0 version of the FBSDKLoginKit pod used by the flutter_facebook_login package.

    opened by dev-mush 10
  • flutter_facebook_login plugin.h not found while building archive for appstore

    flutter_facebook_login plugin.h not found while building archive for appstore

    I am getting error while building archive

    ..../Runner/GeneratedPluginRegistrant.m:6:9: 'flutter_facebook_login/FacebookLoginPlugin.h' file not found
    

    while the app builds and runs successfully on ios heres the flutter doctor -v output

    [✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.14.6 18G1012, locale en-IN)
        • Flutter version 1.9.1+hotfix.6 at /Users/almac03/Documents/flutter
        • Framework revision 68587a0916 (3 months ago), 2019-09-13 19:46:58 -0700
        • Engine revision b863200c37
        • Dart version 2.5.0
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        • Android SDK at /Users/almac03/Library/Android/sdk
        • Android NDK location not configured (optional; useful for native profiling support)
        • Platform android-29, build-tools 29.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 11.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 11.0, Build version 11A420a
        • CocoaPods version 1.7.5
    
    [✓] Android Studio (version 3.4)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 39.0.1
        • Dart plugin version 183.6270
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    
    [✓] VS Code (version 1.40.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.7.0
    
    [✓] Connected device (1 available)
        • iPhone 11 Pro Max • B1D782BE-C888-47D1-9BF7-91F523DF5A68 • ios •
          com.apple.CoreSimulator.SimRuntime.iOS-13-0 (simulator)
    
    • No issues found!
    
    opened by maheshmnj 8
  • The plugins flutter_facebook_login use a deprecated version of the Android embedding how i can solve it ??

    The plugins flutter_facebook_login use a deprecated version of the Android embedding how i can solve it ??

    The plugins `flutter_facebook_login, use a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these
    deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

    opened by Abdo2021-a 0
  • I wanna want to know is this Plugin still support latest Facebook SDK..?

    I wanna want to know is this Plugin still support latest Facebook SDK..?

    Update FB Login SDK to version 8.2+ by Oct. 5 | Update FB Login SDK to version 8.2+ by Oct. 5 |   -- | -- | -- Update FB Login SDK to version 8.2+ by Oct. 5     We have been monitoring an uptick in phishing attempts on Android embedded browsers (also known as web views), so beginning on October 5th, we will no longer support FB Login authentication on Android embedded browsers. Prior to this date, we will continue to prevent access to Facebook Login on embedded browsers for certain users we deem high-risk in an effort to prevent malicious activity. | We have been monitoring an uptick in phishing attempts on Android embedded browsers (also known as web views), so beginning on October 5th, we will no longer support FB Login authentication on Android embedded browsers. Prior to this date, we will continue to prevent access to Facebook Login on embedded browsers for certain users we deem high-risk in an effort to prevent malicious activity. We have been monitoring an uptick in phishing attempts on Android embedded browsers (also known as web views), so beginning on October 5th, we will no longer support FB Login authentication on Android embedded browsers. Prior to this date, we will continue to prevent access to Facebook Login on embedded browsers for certain users we deem high-risk in an effort to prevent malicious activity.

    opened by marslannasr7koncepts 7
  • error in flutter

    error in flutter

    C:\src\flutter\bin\flutter.bat --no-color build apk The plugin flutter_facebook_login uses a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

    Building with sound null safety

    Running Gradle task 'assembleRelease'...
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 lib/pages/add_message_page.dart:1:1: Error: A library can't opt out of null safety by default, when using sound null safety. // @dart=2.9 ^^^^^^^^^^^^ Error: Cannot run with sound null safety, because the following dependencies don't support null safety:

    • package:flutter_facebook_login
    • package:flutter_emoji

    For solutions, see https://dart.dev/go/unsound-null-safety

    FAILURE: Build failed with an exception.

    • Where: Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

    • What went wrong: Execution failed for task ':app:compileFlutterBuildRelease'.

    Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    • Get more help at https://help.gradle.org

    BUILD FAILED in 36s Running Gradle task 'assembleRelease'... 37.3s Gradle task assembleRelease failed with exit code 1

    opened by sadiabbas1122 1
Releases(3.0.0)
Owner
Iiro Krankka
Iiro Krankka
A Flutter wrapper for AppAuth iOS and Android SDKs

flutter_appauth A Flutter plugin that provides a wrapper for native AppAuth SDKs (https://appauth.io) used authenticating and authorizing users. The r

Michael Bui 230 Dec 21, 2022
The Simplest way to Authenticate in Flutter

Most apps need to make API calls. Every API needs authentication, yet no developer wants to deal with authentication. Simple Auth embeds authenticatio

James Clancey 340 Dec 25, 2022
100% Shared Code Android/iOS Login Example - JSON API

Flutter Login Example This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset f

Rody Davis 670 Dec 21, 2022
A simple animated login UI with teddy

Animated Login UI with Teddy ?? Used Packages ✨ flare_flutter How to run First clone the repo: git clone https://github.com/KauaLimaMartins/Teddy-Anim

KauãDev 42 Nov 19, 2022
Flutter Plugin for Sign In with Apple

Apple Sign In - Flutter Plugin Access Sign In with Apple from Flutter. Platform support This plugin currently only supports iOS. There's a JavaScript

Tom Gilder 156 Dec 28, 2022
Flutter Password Validator package helps you to validate user-entered passwords in your flutter app.

Flutter Password Validator Flutter Password Validator package helps you to validate sign-in user-entered passwords with your rules.

Aref Mozafari 26 Dec 14, 2022
Email and Password Authentication In Flutter & Firebase in Flutter 2.2

email_password_flutter_firebase Email and Password Authentication In Flutter & Firebase in Flutter 2.2 Overview This email and password authentication

null 0 Mar 24, 2022
A Flutter OAuth package for performing user authentication for your apps.

Flutter OAuth A Flutter OAuth package for performing user authentication for your apps. I've tested this with a small collection of APIs (Buffer, Stra

Joe Birch 173 Dec 9, 2022
An OAuth authentication system built in Flutter using Google OAuth.

An OAuth authentication system built in Flutter using Google OAuth.

Kaushal 0 Sep 20, 2021
Flutter implementation of the Quickstart Supabase User Management app.

Supabase Flutter User Management This repo is a quick sample of how you can get started building apps using Flutter and Supabase. You can find a step

Supabase Community 56 Nov 14, 2022
This project is an example of Firebase authentication in a flutter

This project is an example of Firebase authentication in a flutter. This project shows how to implement a full authentication flow in Flutter, using sign Up with email and password, sign in with email and password, and reset password.

Nittin 4 Mar 11, 2022
A Flutter package that implements Google Sign In in pure Dart.

A Flutter package that implements Google Sign In in pure Dart. This package is compatible with google_sign_in plugin and works on all platforms Flutter supports but it's intended to be mainly used on Desktop.

Razvan Lung 10 Oct 26, 2022
WebView OAuth flows for desktop flutter apps

desktop_webview_auth A new flutter plugin project. Getting Started This project is a starting point for a Flutter plug-in package, a specialized packa

Invertase 22 Dec 17, 2022
Easy third party authentication (OAuth 2.0) for Flutter apps.

visa This is an OAuth 2.0 package that makes it super easy to add third party authentication to flutter apps. It has support for FB, Google, LinkedIn,

Emmanuel Olaojo 135 Dec 23, 2022
Authentication pages I made with Flutter and Firebase

Auth-with-Flutter-and-Firebase Authentication pages I made with Flutter and Firebase Overview This email and password authentication is implemented wi

Said Mirzayev 3 Jul 24, 2022
An example of JWT authentication with flutter.

flutter-jwt-auth-template An example of JWT authentication with flutter. Getting Started Clone this repository, and inside its folder, run: flutter pu

Enzo Di Tizio 23 Jan 4, 2023
In this Application Built Using Flutter🎯 along with FireBase 🔥for Managing the data

In this Application Built Using Flutter?? along with FireBase ??for Managing the data, I have Curated a simple?? Login/Sign Up Space along with Authentication!

Aashvi Kothari 4 Oct 9, 2022
A Flutter plugin for authenticating users by using the native TwitterKit SDKs on Android & iOS.

flutter_twitter_login A Flutter plugin for using the native TwitterKit SDKs on Android and iOS. This plugin uses the new Gradle 4.1 and Android Studio

Iiro Krankka 83 Sep 15, 2022
Authentication API client with Flutter (Login, Register, Google Login, Facebook Login, Apple Login)

Flutter Auth App (Login, Register, Google Login, Facebook Login, Apple Login) To use this client, get the server up and running. Try it out now! App S

Denzel Giraldo 50 Jan 4, 2023
Facebook based-app - A Facebook based app which actually looks like Facebook

Facebook based mobile application This project is a mobile application which act

Munem Sarker 3 Nov 23, 2022