roughike / flutter_facebook_login

A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs.
BSD 2-Clause "Simplified" License
405 stars 331 forks source link

Login Failure on new Android 9.0 #156

Closed Ismaeils closed 4 years ago

Ismaeils commented 5 years ago

When clicking on the button, it shows a little dialog where I should continue with my opened FB account. After clicking on continue the dialog disappears and nothing happens. These errors come up and no API response. Any idea on how to solve this?

This is the function used for logging in:

`_loginWithFB() async{ print("FUNCTION ENTERED"); final result = await facebookLogin.logInWithReadPermissions(['email']);

switch (result.status) {
  case FacebookLoginStatus.loggedIn:
    final token = result.accessToken.token;

    final graphResponse = await http.get('https://graph.facebook.com/v2.12/me?fields=friends,picture,first_name,email&access_token=${token}');

    final profile = JSON.jsonDecode(graphResponse.body);

    print(profile);
    GlobalUser = User.fromJson(profile);
    print("Name:::::> ${GlobalUser.name}");
    List<User> friends = [user1,user2,user3,user4];
    GlobalUser.friendList = friends;
    AuthCredential credential= FacebookAuthProvider.getCredential(accessToken: token);

    // this line do auth in firebase with your facebook credential.
    FirebaseUser firebaseUser = await FirebaseAuth.instance.signInWithCredential(credential);
    setState(() {
      _isLoggedIn = true;
      //Navigator.push(context, new MaterialPageRoute(builder: (context) => homePage()));
    });
    break;

  case FacebookLoginStatus.cancelledByUser:
    setState(() => _isLoggedIn = false );
    break;
  case FacebookLoginStatus.error:
    setState(() => _isLoggedIn = false );
    break;
}

}`

This is the error log when tried the app on Android 9.0:

I/flutter (26504): FUNCTION ENTERED W/ActivityThread(26504): handleWindowVisibility: no activity for token android.os.BinderProxy@8c86c5c I/DecorView(26504): createDecorCaptionView >> DecorView@dc248e1[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true D/InputTransport(26504): Input channel constructed: fd=113 D/ViewRootImpl@e376bf2FacebookActivity: setView = DecorView@dc248e1[FacebookActivity] TM=true MM=false D/ViewRootImpl@8a357a4MainActivity: MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@680e8e0[MainActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 D/ViewRootImpl@e376bf2FacebookActivity: dispatchAttachedToWindow D/ViewRootImpl@e376bf2FacebookActivity: Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x7 surface={valid=true 534817976320} changed=true D/mali_winsys(26504): EGLint new_window_surface(egl_winsys_display , void , EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000 D/OpenGLRenderer(26504): eglCreateWindowSurface = 0x7cb6579380, 0x7c85a2b010 D/ViewRootImpl@e376bf2FacebookActivity: MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@dc248e1[FacebookActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@dc248e1[FacebookActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 V/InputMethodManager(26504): Starting input: tba=com.larva.e3trefly ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager(26504): startInputInner - Id : 0 I/InputMethodManager(26504): startInputInner - mService.startInputOrWindowGainedFocus D/InputTransport(26504): Input channel constructed: fd=120 D/InputTransport(26504): Input channel destroyed: fd=112 D/ViewRootImpl@e376bf2FacebookActivity: MSG_RESIZED: frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 63 - 0, 126) vi=Rect(0, 63 - 0, 126) or=1 D/ViewRootImpl@e376bf2FacebookActivity: MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@dc248e1[FacebookActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 D/InputTransport(26504): Input channel destroyed: fd=120 D/ViewRootImpl@e376bf2FacebookActivity: MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@dc248e1[FacebookActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@dc248e1[FacebookActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 V/InputMethodManager(26504): Starting input: tba=com.larva.e3trefly ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager(26504): startInputInner - Id : 0 I/InputMethodManager(26504): startInputInner - mService.startInputOrWindowGainedFocus D/InputTransport(26504): Input channel constructed: fd=115 D/ViewRootImpl@8a357a4MainActivity: setWindowStopped(false) old=false D/ViewRootImpl@8a357a4MainActivity: MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@680e8e0[MainActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@680e8e0[MainActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 V/InputMethodManager(26504): Starting input: tba=com.larva.e3trefly ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager(26504): startInputInner - Id : 0 I/InputMethodManager(26504): startInputInner - mService.startInputOrWindowGainedFocus D/InputTransport(26504): Input channel constructed: fd=120 D/InputTransport(26504): Input channel destroyed: fd=115 D/ViewRootImpl@e376bf2FacebookActivity: MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager(26504): prepareNavigationBarInfo() DecorView@dc248e1[FacebookActivity] D/InputMethodManager(26504): getNavigationBarColor() -855310 D/ViewRootImpl@e376bf2FacebookActivity: setWindowStopped(true) old=false W/libEGL (26504): EGLNativeWindowType 0x7c85a2b010 disconnect failed D/OpenGLRenderer(26504): eglDestroySurface = 0x7cb6579380, 0x7c85a2b000 D/ViewRootImpl@e376bf2FacebookActivity: dispatchDetachedFromWindow D/ViewRootImpl@e376bf2FacebookActivity: Surface release. android.view.ViewRootImpl.doDie:7956 android.view.ViewRootImpl.die:7924 android.view.WindowManagerGlobal.removeViewLocked:497 android.view.WindowManagerGlobal.removeView:435 android.view.WindowManagerImpl.removeViewImmediate:124 android.app.ActivityThread.handleDestroyActivity:4748 android.app.servertransaction.DestroyActivityItem.execute:39 android.app.servertransaction.TransactionExecutor.executeLifecycleState:145 D/InputTransport(26504): Input channel destroyed: fd=113 D/ViewRootImpl@e376bf2FacebookActivity: Surface release. android.view.ViewRootImpl$ViewRootHandler.handleMessage:4802 android.os.Handler.dispatchMessage:106 I/System.out(26504): (HTTPLog)-Static: isSBSettingEnabled false I/System.out(26504): (HTTPLog)-Static: isSBSettingEnabled false

Ismaeils commented 5 years ago

This is Solved only when forcing the behavior to log in through webViewOnly only, is there is any way to do it natively(The little dialogue)?

pokkeerr commented 5 years ago

@IsmaeilGhouneim Same issue ? #157 ?

Ismaeils commented 5 years ago

Yes, it seemingly is, and it doesn't happen on any emulator regardless of the version, is something that must do with the latest update for android 9.0. I've actually encountered it first when I submitted my app to the App Review in facebook and the testers weren't able to access my app at all because they couldn't even get passed the login screen. And as you've mentioned in your issue, google sign in is fine. It's something that has to do with facebook sign in dialogue and I can't seem to figure it out till now.

parth22 commented 5 years ago

same issue when i'm using var facebookLogin = FacebookLogin(); facebookLogin.loginBehavior = FacebookLoginBehavior.nativeOnly;

but it's working when i'm using. var facebookLogin = FacebookLogin(); facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;

Ismaeils commented 5 years ago

Okay so guys, I may have found the issue. First of all, download the Facebook app on the phone you're testing it on. The problem is with the key hashes, they weren't matching to the app's settings on the Facebook dashboard. Once I added the correct key hash, It worked natively!

Unfortunately, the error that happens doesn't get printed as a response in the flutter console. and it doesn't show that on the mobile because of the native dialogue, it does show up though on Android Oreo when I downloaded the Facebook app(I didn't have it at the beginning). It did give me an error talking about that the Hash Keys are not matching.

I still don't get why it works with no problem when setting it to webViewOnly, but it seems that the hash keys have something to do with the Facebook App itself and how it reacts natively.

You need to generate the key hash for your app using Keytool This is where you can know how to use Keytool to generate the key: How to create android facebook key hash After you get the correct key hash, go on facebook's developer dashboard for your app: Go to Settings > Basic > scroll down to Android > you'll find a field named Key Hashes and add your key in there.

This is the thread for the error that the facebook finally gave me: Invalid key hash. The key hash does not match any stored key hashes.

I hope this helps!

roughike commented 4 years ago

@IsmaeilGhouneim It seems you were able to resolve the issue, so I'm closing this issue ticket. Glad you were able to solve it!