darwin-morocho / flutter-facebook-auth

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

"During Login, your app is crashing" #238

Closed erperejildo closed 2 years ago

erperejildo commented 2 years ago

Describe the bug Maybe it's not 100% related to this dependency but this is what I see while testing my app:

1

I got this message recently but I have to say that my code was working fine and I didn't update anything. Facebook support doesn't give any clue and they keep saying that login is not working when they review the app (without any other help).

I use Flutter and this package: https://pub.dev/packages/flutter_facebook_auth But I don't think code/framework/package is related at all to this issue. Probably more related to the key hash but this is also updated by this command:

keytool -exportcert -alias key -keystore assets/.keystore | openssl sha1 -binary | openssl base64

My key hash starts like this:

2

But Facebook's "support" shows me this snapshot from its test:

3

Why is it different? Is it because I cannot move my app to Live mode?:

4

That's because of this:

We've disabled this app for violating the Facebook Platform Policies. You can continue to use it in development mode.

Then, looking into that the problem is this:

5

Ok, so the problem is During Login, your app is crashing. Fine, but how should I fix it?

Despite I don't think this is related this is my login function:

    Future facebookSignIn(BuildContext context) async {
        final LoginResult result = await FacebookAuth.instance.login();

        if (result.status == LoginStatus.success) {
          final AccessToken accessToken = result.accessToken!;
          AuthCredential credential =
              FacebookAuthProvider.credential(accessToken.token);
// at this point the user is already logged in but I save history in db
          await _firebaseCredential(context, credential);
        }
      }

Environment Add your flutter doctor -v:

[✓] Flutter (Channel stable, 2.10.3, on macOS 11.6.5 20G527 darwin-x64, locale en-GB)
    • Flutter version 2.10.3 at /Users/dani/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (9 weeks ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/dani/Library/Android/sdk/
    • Platform android-Sv2, build-tools 30.0.3
    • ANDROID_HOME = /Users/dani/Library/Android/sdk/
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.66.2)
    • VS Code at /Users/dani/Desktop/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.54

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

• No issues found!

Add your pubspec.yaml:

name: my_rents
description: Manage your properties and their rents easily

version: 3.8.9+3.8.9

environment:
  sdk: ">=2.15.1 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  line_icons: ^2.0.1
  dapackages: ^1.6.0 # keeps packages updated: flutter pub pub run dapackages:dapackages.dart ./pubspec.yaml
  flutter_cupertino_localizations: ^1.0.1
  flutter_google_places: ^0.3.0
  maps_launcher: ^2.0.1 # REMOVED, USE OTHER INSTEAD
  uuid: ^3.0.5 # IDs for events
  cloudinary_public: ^0.11.0
  showcaseview: ^1.1.4 # help for new users
  provider: ^6.0.1
  cloud_firestore: ^3.1.5
  firebase_core: ^1.10.6 # needs Runner/GoogleService-Info.plist
  firebase_auth: ^3.3.4 # needs Runner/GoogleService-Info.plist
  firebase_analytics: ^9.0.4 # needs Runner/GoogleService-Info.plist
#  firebase_crashlytics: ^2.4.3 # needs Runner/GoogleService-Info.plist and NSAppTransportSecurity in Info.plist
  http: ^0.13.4
  badges: ^2.0.2
  flutter_translate: ^3.0.1
  flutter_facebook_auth: ^4.1.2
  google_sign_in: ^5.2.1 # needs Info.plist modification
  sign_in_with_apple: ^3.3.0  # needs Xcode modification https://pub.dev/packages/sign_in_with_apple
  shared_preferences: ^2.0.10
  share_plus: ^3.0.4
  intl: ^0.17.0 # locales for table_calendar and datetime manipulation
  jiffy: ^4.1.0 # date manipulation
  permission_handler: ^8.3.0 # needs Info.plist modification
  csv: ^5.0.1
  path_provider: ^2.0.8
  package_info_plus: ^1.3.0
  after_init: ^0.1.2 # NO NULL
  flutter_email_sender: ^5.0.2
  flutter_launcher_icons: ^0.9.2
  #  NEEDS TO BE UPDATED
  file_picker: ^4.2.7 # for multiple images selection
  image_picker: ^0.8.4+4 # for camera
  image: ^3.1.0
  url_launcher: ^6.0.17 # needs Info.plist modification
  transparent_image: ^2.0.0
  cached_network_image: ^3.2.0
  carousel_slider: ^4.0.0
  flutter_slidable: 1.0.0-dev.9
  flutter_svg: ^1.0.0
  table_calendar: ^3.0.3
  add_2_calendar: ^2.1.2 # Info.plist modification
  #  NEEDS TO BE UPDATED
  in_app_purchase: ^3.0.2 # official one.
  device_info_plus: ^3.1.1
  flutter_platform_widgets: ^1.12.0
  flutter_native_splash: ^1.3.2
  intl_phone_number_input: ^0.7.0+2  # NO NULL
  country_pickers: ^2.0.0
  currency_picker: ^2.0.7
  #  country_currency_pickers: ^1.0.1 # NO NULL
  reorderables: ^0.4.2 # NO NULL reorder rent fields
  drag_and_drop_gridview: ^1.0.8 # NO NULL
  pdf: ^3.6.5
  printing: ^5.6.6 # necessary for the above one
  open_file: ^3.2.1 # necessary for the above one
  #  flutter_statusbarcolor_ns: ^0.4.0 # DO NOT CHANGE
  fimber: ^0.6.4
  fluttercontactpicker: ^4.6.0
  contacts_service: ^0.6.3 # get contacts. Info.plist modification
  stack_appodeal_flutter: 1.2.0

# generate new splashscreen: flutter pub run flutter_native_splash:create
# flutter pub run flutter_native_splash:remove
flutter_native_splash:
  image: assets/images/splashscreen.png
  color: '281b60'
  fill_horizontal: true

# generate new icon: flutter pub run flutter_launcher_icons:main
flutter_icons:
  android: true
  ios: true
  image_path: assets/images/icon.png
  #  adaptive_icon_background: assets/images/icon.png
  #  adaptive_icon_background: '281B60'
  #  image_path_ios: 'assets/images/icon.png'
  #  image_pathandroid: 'assets/images/icon.png'
#  adaptive_icon_foreground: assets/images/icon.png

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - assets/i18n/
    - assets/images/
    - assets/images/versions/
    - assets/images/other-apps/
    - assets/icons/
    - assets/fonts/
  fonts:
    - family: MontserratMedium
      fonts:
        - asset: assets/fonts/Montserrat-Medium.ttf

Add your `MainActivity:

package com.drodriguez.my_rents

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

Add your AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.drodriguez.my_rents">
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
        <intent>
            <action android:name="android.intent.action.INSERT" />
            <data android:mimeType="vnd.android.cursor.item/event" />
        </intent>
    </queries>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="com.android.vending.BILLING" />

    <application
        android:label="My Rents"
        tools:replace="android:label"
        android:name="${applicationName}"
        android:networkSecurityConfig="@xml/network_security_config"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            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"
            android:exported="true">
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
                />
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background"
                />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Firebase performance-->
        <meta-data
            android:name="firebase_performance_logcat_enabled"
            android:value="true" />

        <!-- Facebook Login configuration -->
        <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="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:exported="true"
            />

        <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>

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-2945024608555072~6845412431"/>
    </application>
</manifest>

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

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My Rents</string>
    <string name="facebook_app_id">842729662973086</string>
    <string name="fb_login_protocol_scheme">fb842729662973086</string>
    <string name="facebook_client_token">39bcaee6bc8b3066ee348056246a7ba8</string>
</resources>

To Reproduce Try log in with Facebook on released app

Expected behavior I shouldn't see any error

Screenshots Added above

darwin-morocho commented 2 years ago

@erperejildo I've run the example app using flutter run --release and it works.

Try to upgrade to the last version of this plugin. keep in mind that starting with the version 4.2.0 the android manifest configuration has been changed. Go to the documentation to check that changes

this seems an error with your hashes. You should go to your facebook console and check if you don't have some notification of the facebook team, also check your key hashes

erperejildo commented 2 years ago

@erperejildo I've run the example app using flutter run --release and it works.

Try to upgrade to the last version of this plugin. keep in mind that starting with the version 4.2.0 the android manifest configuration has been changed. Go to the documentation to check that changes

this seems an error with your hashes. You should go to your facebook console and check if you don't have some notification of the facebook team, also check your key hashes

I'll try to use latest version, ok. What do you mean with Facebook console? I can only see this place to put the hash:

https://user-images.githubusercontent.com/5629919/166911150-e9e16dea-8c9f-4cda-a969-d6797bd250bd.png

darwin-morocho commented 2 years ago

@erperejildo I've run the example app using flutter run --release and it works. Try to upgrade to the last version of this plugin. keep in mind that starting with the version 4.2.0 the android manifest configuration has been changed. Go to the documentation to check that changes this seems an error with your hashes. You should go to your facebook console and check if you don't have some notification of the facebook team, also check your key hashes

I'll try to use latest version, ok. What do you mean with Facebook console? I can only see this place to put the hash:

https://user-images.githubusercontent.com/5629919/166911150-e9e16dea-8c9f-4cda-a969-d6797bd250bd.png

My suggestion is run the app in android studio and use the logcat to show the error when the app crash, because I'm sure that the error is not due to this plugin

erperejildo commented 2 years ago

@erperejildo I've run the example app using flutter run --release and it works. Try to upgrade to the last version of this plugin. keep in mind that starting with the version 4.2.0 the android manifest configuration has been changed. Go to the documentation to check that changes this seems an error with your hashes. You should go to your facebook console and check if you don't have some notification of the facebook team, also check your key hashes

I'll try to use latest version, ok. What do you mean with Facebook console? I can only see this place to put the hash: https://user-images.githubusercontent.com/5629919/166911150-e9e16dea-8c9f-4cda-a969-d6797bd250bd.png

My suggestion is run the app in android studio and use the logcat to show the error when the app crash, because I'm sure that the error is not due to this plugin

the thing is I don't see any issue while testing the app myself. And yes, it's probably more related to Facebook itself and its configuration but when asking the staff they keep saying it doesn't work and if the hash is not updated I should ask on its forum (and no one never reply there).

I guess it could more people like without the necessary support to fix it. Any explanation to understand why they see different key hash while testing my app?

darwin-morocho commented 2 years ago

@erperejildo I've run the example app using flutter run --release and it works. Try to upgrade to the last version of this plugin. keep in mind that starting with the version 4.2.0 the android manifest configuration has been changed. Go to the documentation to check that changes this seems an error with your hashes. You should go to your facebook console and check if you don't have some notification of the facebook team, also check your key hashes

I'll try to use latest version, ok. What do you mean with Facebook console? I can only see this place to put the hash: https://user-images.githubusercontent.com/5629919/166911150-e9e16dea-8c9f-4cda-a969-d6797bd250bd.png

My suggestion is run the app in android studio and use the logcat to show the error when the app crash, because I'm sure that the error is not due to this plugin

the thing is I don't see any issue while testing the app myself. And yes, it's probably more related to Facebook itself and its configuration but when asking the staff they keep saying it doesn't work and if the hash is not updated I should ask on its forum (and no one never reply there).

I guess it could more people like without the necessary support to fix it. Any explanation to understand why they see different key hash while testing my app?

if your app is in debug mode some time the key hash returned by the command is wrong

keytool -exportcert -alias key -keystore assets/.keystore | openssl sha1 -binary | openssl base64

in that case you can get the correct hey hash using native code

https://developers.facebook.com/docs/facebook-login/android/troubleshooting?locale=en_US

erperejildo commented 2 years ago

I used latest version and didn't help:

Screenshot 2022-05-05 at 23 39 28

Locally it complains now about this review stage but I can't send it without this fixed.

"you can get the correct hey hash using native code". I don't understand this even after reading that. Is there any possible way to do that from Flutter?

darwin-morocho commented 2 years ago

are you saying that the login flow works fine but it shows a warning in that case you need to send a request to Facebook to be able to use the permissions that you are requesting to the user. as another hand In pub.dev you can find some packages to get the correct key hash

I' sorry man but I cannot help you more with this because is not an issue of this plugin.

please considere close this issue.

erperejildo commented 2 years ago

"are you saying that the login flow works fine but it shows a warning". That's correct "you need to send a request to Facebook to be able to use the permissions". But that's not possible. First of all because if request more permissions I'll need to send the app for review and they will reject it. Second, I don't need extra permissions, for me it works as it is. "In pub.dev you can find some packages to get the correct key hash". Can you point me to that? I thought that was only possible but that command I shared above.

I'll close the ticket in the meantime since it's not related

erperejildo commented 2 years ago

keytool -exportcert -alias key -keystore assets/.keystore | openssl sha1 -binary | openssl base64

is the command I used and that is still showing the "wrong" hash

darwin-morocho commented 2 years ago

keytool -exportcert -alias key -keystore assets/.keystore | openssl sha1 -binary | openssl base64

is the command I used and that is still showing the "wrong" hash

As I mentioned before in debug mode some times that command not works, try to use native code and android studio (WITH LOCAT) to get the correct hash

https://stackoverflow.com/questions/54657148/facebook-login-problem-with-hash-key-flutter-how-to-generate-facebook-hashk

erperejildo commented 2 years ago

https://stackoverflow.com/questions/54657148/facebook-login-problem-with-hash-key-flutter-how-to-generate-facebook-hashk

I tried that an specific package to show it and I get the same key hash I already had in Facebook