darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
193 stars 127 forks source link

CONNECTION_FAILURE: CONNECTION_FAILURE Login Failed #227

Closed afzl-wtu closed 2 years ago

afzl-wtu commented 2 years ago

Describe the bug I have imported latest package (flutter_facebook_auth: ^4.1.2) and followed all the documentaion on the website https://facebook.meedu.app/ for android. Now when I click on "sign in with facebook" Button . It takes me to facebook app where I allow the authorization. After this it closes and I am shifted back to app But I am not signed in the app. I got the following output from the debug Console: PP: result.status: Login Failed PP: result.message: CONNECTION_FAILURE: CONNECTION_FAILURE

I confirm internet is working fine and even I used vpn to check if it is problem of my local internet. I even cleared my cache by flutter clean command. I have also added required fields on facebook including SHA-1 in form of Base64 and turned on facebook authentication.

To Reproduce Flutter Code:

 Future<String?>? _signInWithFacebook() async {
    final LoginResult result = await FacebookAuth.instance
        .login();
    if (result.status == LoginStatus.success) {
      print(' Logged In');
    } else {
      print('PP: result.status ${result.status}');
      print('PP: result message: ${result.message}');
    }

Environment Add your flutter doctor -v

[√] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.22000.556], locale en-GB)
    • Flutter version 2.10.4 at C:\Users\Public\@Apps\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (2 weeks ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at C:\Users\afzlw\AppData\Local\Android\sdk
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.        
      27) (emulator)
    • Windows (desktop)                  • windows            • windows-x64    • Microsoft Windows    
      [Version 10.0.22000.556]
    • Edge (web)                         • edge               • web-javascript • Microsoft Edge       
      100.0.1185.29

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 3 categories.

Add your pubspec.yaml

name: dot_now
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: ">=2.16.2 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: ^3.1.11
  cupertino_icons: ^1.0.2
  easy_mask: ^2.0.1
  firebase_auth: ^3.3.12
  firebase_core: ^1.14.0
  flutter_countdown_timer: ^4.1.0
  firebase_database: ^9.0.9
  flutter_facebook_auth: ^4.1.2
  flutter_signin_button: ^2.0.0
  flutter_svg: ^1.0.3
  fluttertoast: ^8.0.9
  google_fonts: ^2.3.1
  google_sign_in: ^5.2.4
  introduction_screen: ^3.0.2
  pinput: ^2.2.7
  sembast: ^3.2.0
  sentry: ^6.4.0
  vxstate: ^2.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^1.0.0
flutter:
  uses-material-design: true
  assets:
    - assets/svg/landing_page/

Add your Info.plist

Not relevent as I am testing for android only.

Add your AppDelegate.swift

Not relevent as I am testing for android only.

Add your MainActivity

package pk.dotnow.dot_now

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

Add your AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="pk.dotnow.dot_now">
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>

   <application
        android:label="dot_now"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <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"/>
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Add your /app/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="facebook_app_id">516060370HIDDEN</string>
    <string name="facebook_client_token">c95ccef4b55f41dcd80289c849HIDDEN</string>
</resources>
darwin-morocho commented 2 years ago

@afzl-wtu if your facebook app is in dev mode You should use test accounts or use the same facebook account that you have used to create the app in the facebook developer console

afzl-wtu commented 2 years ago

I am using test account and developer account.

darwin-morocho commented 2 years ago

Also try to use mobile data instead of wifi

afzl-wtu commented 2 years ago

Lol... so if people are using wifi they can not login through facebook?

afzl-wtu commented 2 years ago

Google Sign In and Google Phone Authentication is working fine. but only facebook fails.

darwin-morocho commented 2 years ago

Lol... so if people are using wifi they can not login through facebook?

That doesn't depend of this plugin, sometimes you can have blocks due to your internet provider , or block by country or even a wrong configuration in your dev console

afzl-wtu commented 2 years ago

I see. Facebook is working fine in my web browser and facebook app. That is why even I switched to VPN based in germany. Can you reproduce the error on latest package version?

darwin-morocho commented 2 years ago

https://facebook.meedu.app/

before release a new version I have tested on android and ios.

Also try to use a different login behavior when you call login use LoginBehavior.nativeWithFallback , and if you think is a bug of the current facebook sdk try to use a previous version of this plugin and let me known if the error persists

afzl-wtu commented 2 years ago

Tried LoginBehavior.nativeWithFallback and 4.0.1 but still failed.

darwin-morocho commented 2 years ago

Tried LoginBehavior.nativeWithFallback and 4.0.1 but still failed.

It seems that this issue should be here https://github.com/facebook/facebook-android-sdk

afzl-wtu commented 2 years ago

Should I download facebook sdk in my build.gradle or Add any dependency in AndroidManifest.xml file? Because in documentation it is not mentioned anywhere to import any kind of facebook sdk, if I am not wrong.

afzl-wtu commented 2 years ago

My project level build.gradle file:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app level build.gradle file:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

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'

android {
    compileSdkVersion 31

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "pk.dotnow.dot_now"
        minSdkVersion 23
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:29.2.1')
    implementation 'com.google.firebase:firebase-analytics-ktx'
}
darwin-morocho commented 2 years ago

Should I download facebook sdk in my build.gradle or Add any dependency in AndroidManifest.xml file? Because in documentation it is not mentioned anywhere to import any kind of facebook sdk, if I am not wrong.

that is not necessary because by default your project will take all dependencies from flutter_facebook_auth

afzl-wtu commented 2 years ago

Thanks for confirming... Is everything OK in build.gradle file mentioned above and AndroidManifest.xml file?

darwin-morocho commented 2 years ago

also you can clone the example folder and change your facebook credentials and the package name with your app data

if the error persist is something wrong in your facebook developer console or your key hash is invalid

afzl-wtu commented 2 years ago

also you can clone the example folder and change your facebook credentials and the package name with your app data

if the error persist is something wrong in your facebook developer console or your key hash is invalid

I cloned your app it also did not work. My Facebook app was also not working very well. So, after spending my 2 days, I remembered that I had blocked facebook in AdAway (Blocks ads on rooted phones by filtering DNS queries). So I turned it off and Now everything Works out of Box. Thanks for your time and timely help.