darwin-morocho / flutter-facebook-auth

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

mac os login result won't return to app window #304

Closed mostafaAbdelazim closed 1 year ago

mostafaAbdelazim commented 1 year ago

What version are you using?

flutter_facebook_auth: ^5.0.1

What OS and version are you using to local deploy your application?

M1 MBA with macOS 13.0

What platforms are you seeing the problem on?

macOS

pubspec.yaml

name: flutter_login_screen
description: Functional Flutter Starter Kit
version: 1.0.0+1
publish_to: 'none'
environment:
  sdk: ">=2.18.4 <3.0.0"

dependencies:
  firebase_core: ^2.1.1
  firebase_auth: ^4.1.1
  cloud_firestore: ^4.0.4
  firebase_storage: ^11.0.4

  shared_preferences: ^2.0.15
  progress_dialog:
    git:
      url: https://github.com/mostafaAbdelazim/progress_dialog.git
  flutter_facebook_auth: ^5.0.1
  http: ^0.13.5
  image_picker: ^0.8.6
  cached_network_image: ^3.2.2
  smooth_page_indicator: ^1.0.0+2
  the_apple_sign_in: ^1.1.1
  bloc: ^8.1.0
  flutter_bloc: ^8.1.1
  url_launcher: ^6.1.6
  file_picker: ^5.2.2

  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.5

dev_dependencies:
  flutter_launcher_icons: ^0.10.0
  flutter_lints: ^2.0.1

flutter_icons:
  android: false
  ios: true
  remove_alpha_ios: true
  image_path: android/app/src/main/ic_launcher-playstore.png

flutter:
  uses-material-design: true
  assets:
    - assets/images/

Describe the Bug

After typing in the correct login info in the facebook login window, the result won't return to my app. Instead, the login window is displaying my facebook home feed page to browse, see screenshots below

Screenshot 2022-11-06 at 4 55 29 PM Screenshot_2022-11-06_at_4_51_38_PM

Expected Behavior

The login window should close and pass the result back to app window.

To Reproduce

run a flutter app on mac os try to make a login request do the login process on the facebook login window

Relevant log output

No response

flutter doctor -v

doctor --verbose
[✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale en-EG)
    • Flutter version 3.3.7 on channel stable at /Users/mostafaabdelazim/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e99c9c7cd9 (5 days ago), 2022-11-01 16:59:00 -0700
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
    • Android SDK at /Users/mostafaabdelazim/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc1
    • ANDROID_HOME = /Users/mostafaabdelazim/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.2)
    • 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.12+0-b1504.28-7817840)

[✓] VS Code (version 1.59.1)
    • VS Code at /Users/mostafaabdelazim/Downloads/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.0 22A380 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.87

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

• No issues found!
Process finished with exit code 0

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

No response

MainActivity.java

No response

MainActivity.kt

No response

index.html

No response

Info.plist (macOS)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIconFile</key>
    <string></string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSMinimumSystemVersion</key>
    <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
    <key>NSHumanReadableCopyright</key>
    <string>$(PRODUCT_COPYRIGHT)</string>
    <key>NSMainNibFile</key>
    <string>MainMenu</string>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>com.apple.security.network.server</key>
    <true/>
</dict>
</plist>
darwin-morocho commented 1 year ago

@mostafaAbdelazim add your AppDelegate.swift of your macOS folder

mostafaAbdelazim commented 1 year ago

@darwin-morocho Thanks for the quick reply, here's my app delegate

import Cocoa import FlutterMacOS

@NSApplicationMain class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } }

darwin-morocho commented 1 year ago

@mostafaAbdelazim first you need to upgrade to flutter_facebook_auth: 5.0.4 next go to your facebook console > Facebook Login > Settings and make sure you have enabled Login from Devices , Login with the JavaScript SDK and finally check that https://www.facebook.com/ is in your Allowed Domains for the JavaScript SDK

Captura de pantalla 2022-11-06 a la(s) 14 41 50

Sorry, I forgot add that info in https://facebook.meedu.app/docs/5.x.x/macos

mostafaAbdelazim commented 1 year ago

@darwin-morocho I did the above changes, and still the login window is displaying my facebook home feed page after the login is successful

darwin-morocho commented 1 year ago

@darwin-morocho I did the above changes, and still the login window is displaying my facebook home feed page after the login is successful

Please check this example https://github.com/darwin-morocho/flutter-facebook-auth/tree/master/examples/with_provider and change with your app id. If the error persists it seems an error in your facebook console configuration

darwin-morocho commented 1 year ago

@darwin-morocho I did the above changes, and still the login window is displaying my facebook home feed page after the login is successful

Please check this example https://github.com/darwin-morocho/flutter-facebook-auth/tree/master/examples/with_provider and change with your app id. If the error persists it seems an error in your facebook console configuration

Here you have my configuration

Screenshot_20221106_181750_com android chrome

mostafaAbdelazim commented 1 year ago

@darwin-morocho Thanks for the detailed help, I've adjusted my facebook console to match yours, now i'm facing a new error (Even tried to login from the provided example and got the same error), here's the full logs:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value

0 FacebookAuthDesktopPlugin.login (package:facebook_auth_desktop/facebook_auth_desktop.dart:135:50)

-1 _LoginPageState._login (package:flutter_facebook_auth_example/src/ui/pages/login/views/login_page.dart:55:20) it's pointing to line 135 in the facebook_auth_desktop.dart file final token = arguments['long_lived_token']!;
darwin-morocho commented 1 year ago

@mostafaAbdelazim try with v15.0 instead v14.0

  if (kIsWeb || defaultTargetPlatform == TargetPlatform.macOS) {
    await FacebookAuth.i.webAndDesktopInitialize(
      appId: 'YOUR_APP_ID',
      cookie: true,
      xfbml: true,
      version: "v15.0",
    );
  }

Also flutter_facebook_auth:5.0.5 has fixed the error Null check operator used on a null value

mostafaAbdelazim commented 1 year ago

@darwin-morocho Looking good man, I'm running into new errors, the login state is successful, i can see the token from the LoginResult object but when i try to access the token from: await facebookAuth.accessToken();

the token is null, and getUserData() functions returns empty map since it's using the null accessToken

I believe it's for some reason the accessToken is not written in the secure storage, I've already enabled keychain sharing capability, any help would be appreciated.

darwin-morocho commented 1 year ago

keychain sharing capability,

keychain sharing capability needs a developer team. In xcode make sure that keychain sharing capability is really added

mostafaAbdelazim commented 1 year ago

@darwin-morocho

Screenshot 2022-11-08 at 2 34 27 AM
darwin-morocho commented 1 year ago

@darwin-morocho Screenshot 2022-11-08 at 2 34 27 AM

check flutter_facebook_auth:5.0.6

mostafaAbdelazim commented 1 year ago

Great job @darwin-morocho, I've tested version 5.0.6 and it's working as intended, Thank you so much.

milhomem commented 9 months ago

I'm having a similar issue where it keeps showing me Can't load URL . I've tried every single possible configuration on Facebook Console and cannot log in on debug mode.

I'm using: flutter_facebook_auth: ^6.0.1

Screenshot 2023-08-14 at 5 38 59 pm