darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
191 stars 124 forks source link

[macOS] MissingPluginException(No implementation found for method login on channel app.meedu/flutter_facebook_auth) #388

Closed potatojoayo closed 2 months ago

potatojoayo commented 2 months ago

What version are you using?

flutter_facebook_auth:6.0.4

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

macOS 14.2.1

What platforms are you seeing the problem on?

macOS

pubspec.yaml

name: plain_auth
description: "Plain Potato authentication package."
version: 0.0.1
#homepage:

environment:
  sdk: '>=3.2.5 <4.0.0'
  flutter: ">=1.17.0"

dependencies:
  crypto: ^3.0.3
  easy_localization: ^3.0.3
  equatable: ^2.0.5
  firebase_auth: ^4.17.0
  flutter:
    sdk: flutter
  flutter_bloc: ^8.1.3
  flutter_facebook_auth: ^6.0.4
  font_awesome_flutter: ^10.7.0
  google_sign_in: ^6.2.1
  hydrated_bloc: ^9.1.3
  sign_in_with_apple: ^5.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  mocktail: ^1.0.3
  bloc_test: ^9.1.5

flutter:

Describe the Bug

source code

  Future<UserCredential?> login() async {
    final LoginResult loginResult = await _facebookAuth.login();
    if (loginResult.accessToken == null) {
      return null;
    }
    final OAuthCredential facebookAuthCredential =
        FacebookAuthProvider.credential(loginResult.accessToken!.token);

    firebaseAuth ??= FirebaseAuth.instance;

    try {
      return await firebaseAuth!.signInWithCredential(facebookAuthCredential);
    } on FirebaseAuthException catch (e) {
      return await handleFirebaseAuthError(
          e: e,
          firebaseAuth: firebaseAuth!,
          provider: PlainAuthOAuthProviderType.facebook);
    }
  }

Android

Works fine with the same code.

iOS

Works fine with the same code.

macOS

Following exception was thrown.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method login on channel app.meedu/flutter_facebook_auth)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:320:7)
<asynchronous suspension>
#1      FacebookAuthPlatformImplementation.login (package:flutter_facebook_auth_platform_interface/src/facebook_auth_implementation.dart:34:22)
...

I've followed the documentation (https://facebook.meedu.app/docs/6.x.x/macos) throughly and did triple check.

The following snippet was added to macos/runner/info.plist

<key>com.apple.security.network.server</key>
<true/>

Below is Xcode setting. 스크린샷 2024-02-14 오후 1 16 59

Also, facebook login setting was set.

스크린샷 2024-02-14 오후 1 14 55

Finally, I initialized the sdk with the following code.

    if (defaultTargetPlatform == TargetPlatform.macOS) {
      FacebookAuth.i.webAndDesktopInitialize(
        appId: "3823348807877566",
        cookie: true,
        xfbml: true,
        version: "v18.0",
      );
    }

Expected Behavior

Not throw any exception in macOS just like Android and iOS.

To Reproduce

Github repository

https://github.com/Plain-Potato/Plain-Auth

Relevant log output

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method login on channel app.meedu/flutter_facebook_auth)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:320:7)
<asynchronous suspension>
#1      FacebookAuthPlatformImplementation.login (package:flutter_facebook_auth_platform_interface/src/facebook_auth_implementation.dart:34:22)
<asynchronous suspension>
#2      PlainAuthFacebookOAuthProvider.login (package:plain_auth/src/resources/datasources/plain_auth_facebook_oauth_provider.dart:24:37)
<asynchronous suspension>
#3      PlainAuthOAuthRepository.login (package:plain_auth/src/resources/repositories/plain_auth_oauth_repository.dart:54:12)
<asynchronous suspension>
#4      PlainAuthBloc._onLoginRequested (package:plain_auth/src/bloc/plain_auth_bloc.dart:61:9)
<asynchronous suspension>
#5      Bloc.on.<anonymous closure>.handleEvent (package:bloc/src/bloc.dart:229:13)
<asynchronous suspension>

### flutter doctor -v

```shell
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71 darwin-arm64, locale ko-KR)
    • Flutter version 3.16.9 on channel stable at /Users/hanhyobeom/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (3 weeks ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/hanhyobeom/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

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

[✓] Android Studio (version 2023.1)
    • 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
    • android-studio-dir = /Applications/Android Studio.app
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] Connected device (3 available)            
    • iPhone (4) (mobile) • 00008030-001845C40E83802E • ios            • iOS 17.2.1 21C66
    • macOS (desktop)     • macos                     • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)        • chrome                    • web-javascript • Google Chrome 121.0.6167.160

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Info.plist (iOS)

<?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>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>Plain Todo</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleLocalizations</key>
    <array>
        <string>en</string>
        <string>ko</string>
    </array>
    <key>CFBundleName</key>
    <string>Plain TODO</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb***</string>
                <string>***</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>FacebookAppID</key>
    <string>***</string>
    <key>FacebookClientToken</key>
    <string>***</string>
    <key>FacebookDisplayName</key>
    <string>Plain Potato</string>
    <key>GIDClientID</key>
    <string>***</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-share-api</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIApplicationSupportsIndirectInputEvents</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.google.GIDSignIn</string>
    </array>
</dict>
</plist>

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>CFBundleDisplayName</key>
    <string>Plain Todo</string>
    <key>CFBundleName</key>
    <string>Plain TODO</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>10.15</string>
    <key>NSHumanReadableCopyright</key>
    <string>$(PRODUCT_COPYRIGHT)</string>
    <key>NSMainNibFile</key>
    <string>MainMenu</string>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>CFBundleLocalizations</key>
    <array>
        <string>en</string>
        <string>ko</string>
    </array>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb***</string>
                <string>***</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>***</string>
    <key>FacebookClientToken</key>
    <string>***</string>
    <key>FacebookDisplayName</key>
    <string>Plain Potato</string>
    <key>GIDClientID</key>
    <string>***</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-share-api</string>
    </array>
    <key>com.apple.security.network.server</key>
    <true/>
</dict>
</plist>
potatojoayo commented 2 months ago

Solved by using facebook_auth_desktop package.

Before

    final LoginResult loginResult = await _facebookAuth.login();

After

    if (defaultTargetPlatform == TargetPlatform.macOS) {
      _plugin = FacebookAuthDesktopPlugin();
      _plugin.webAndDesktopInitialize(
          appId: '3823348807877566',
          cookie: true,
          xfbml: true,
          version: 'v18.0');

      loginResult = await _plugin.login();
    } else {
      loginResult = await _facebookAuth.login();
    }

New issue

Now that the exception has gone, another bug was found.

2024-02-14 18:40:07.604 plain_todo[12118:3781912] *** Assertion failure in -[facebook_auth_desktop.WebViewController dismissViewController:], NSViewController.m:863
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'dismissViewController:: Error: maybe this view controller was not presented?'

I'll open it as a new issue.

potatojoayo commented 2 months ago

389