roughike / flutter_facebook_login

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

Infinite loop login in Ios #243

Closed nicolobozzato closed 4 years ago

nicolobozzato commented 4 years ago

I'm using flutter_facebook_login: ^3.0.0. A weird thing happen when trying to log in with this plugin if there is also the facebook app installed on an Ios phone. I keep bouncing between webview and app.

The webview is the first to open and asking you to log in with the Facebook app. When you click on the button to open the app, it advises you that you already logged in the flutter app with facebook. But when you press "Continue" it bounces you back to the webview. And the cycle repeats again.

If you press "cancel" at any point it goes out of the loop with status cancelledByUser. I tried to change facebookSignIn.loginBehavior but as written in the comment update login behavior is now ignored on iOS, as it's not supported by the iOS Facebook Login SDK anymore. How could I force eventually the Ios to use only web view?

The login has no problem when no app is installed on the phone.

Future<Null> loginFacebook(BuildContext context) async {
    await logOutFacebook();
    try {
      final result = await InternetAddress.lookup('facebook.com');
      if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
        facebookSignIn.loginBehavior = FacebookLoginBehavior.webViewOnly;
        final FacebookLoginResult result =
            await facebookSignIn.logIn(['email', 'public_profile']); //can't pass on this function
       [...]
  }

Flutter doctor

[✓] Flutter (Channel stable, v1.12.13+hotfix.7, on Mac OS X 10.14.6
    18G87, locale it-IT)

[✓] Android toolchain - develop for Android devices (Android SDK 
    version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.5)
[✓] Connected device (1 available)

• No issues found!

No error are shown

nicolobozzato commented 4 years ago

It seems I found a way to fix it by removing some line from Info.plist I just left in the array

<string>fbapi</string> 

that means I deleted:

    <string>fb-messenger-share-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>

Now my Info.plist only look like this in LSApplicationQueriesSchemes This seems to remove the possibility to the Ios to look for the app.

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
    </array>
[...]
thetpaingsoe commented 4 years ago

@nicolobozzato Thanks, This solve my problem. But this one is only login with webview. How about native app login ? Do you have any idea ?

[Edited] I got issue at logout. I can't logout and can't change to another account to login. Any idea ?

nicolobozzato commented 4 years ago

@thetpaingsoe actually I'm not sure native app login is supported by Ios SDK. In their changelog https://github.com/facebook/facebook-ios-sdk/blob/master/CHANGELOG.md?fbclid=IwAR0mRgOwk-aNVPmWzfWxJKhgXa6vaY4vxaYPkllY5nlB4it6JWLuspD4iW0

I found in the version 6.0 changelog

LoginKit
FBSDKLoginBehavior Login flows no longer support logging in through the native application. This change reflects that.

Regarding your problem with logout, if I understand your issue, I think it depends by the cookies of Safari. So you log out from your app, but everytime you log in in the app it goes with a webview on Safari and retrieve the previous data. So only method to log out from facebook is to logOut in Safari. I'm not sure is possible to manipulate the cookies of Safari from the app IMHO.

shivam-kakkar commented 2 years ago

For anyone facing this issue, I was stuck on this for 3 days and the only file that you need to check in case of infinite loop login is AppDelegate.m. I had issues because I was using multiple social auths and also deep linking. Here's what fixed in my case. If you are using google login or any other social auths add an if condition for them too.

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]) {
    return YES;
  }

  if ([RNGoogleSignin application:application openURL:url options:options]) {
    return YES;
  }

  if ([RCTLinkingManager application:application openURL:url options:options]) {
    return YES;
  }

  return NO;
}