darwin-morocho / flutter-facebook-auth

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

Logint Sucee,but FacebookAuth.instance.accessToken null #369

Closed Lanticee closed 5 months ago

Lanticee commented 5 months ago

What version are you using?

6.0.2

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

macos 14.1.1

What platforms are you seeing the problem on?

macOS

pubspec.yaml

platforms:
  android:
  ios:
  macos:
  windows:

environment:
  sdk: '>=3.1.0 <4.0.0'

dependencies:
  bloc: ^8.1.2
  camera: ^0.10.5+5
  camera_macos: ^0.0.7+2
  camera_windows: ^0.2.1+8
  chewie: ^1.7.1
  comment_box: ^0.0.18
  cupertino_icons: ^1.0.5
  decimal: ^2.3.3
  desktop_window: ^0.4.0
  dio: ^5.3.2
  ffmpeg_kit_flutter_full_gpl: 6.0.3
  file_picker: ^5.3.3
  firebase_auth: ^4.14.0
  flutter:
    sdk: flutter
  flutter_bloc: ^8.1.3
  flutter_facebook_auth: ^6.0.2
  flutter_launcher_icons: ^0.13.1
  font_awesome_flutter: ^10.5.0
  get: ^4.6.5
  get_storage: ^2.1.1
  http: ^1.1.0
  intl: ^0.18.1
  open_filex: ^4.3.2
  path: ^1.8.3
  path_provider: ^2.1.1
  percent_indicator: ^4.2.3
  shared_preferences: ^2.2.0
  video_player: ^2.8.1
  video_player_media_kit: ^1.0.4

Describe the Bug

Login to Facebook is sucess, and get return correct, but at 14.1.1 ,FacebookAuth.instance.accessToken get null, it works at macos before version.

Expected Behavior

FacebookAuth.instance.accessToken work before, if i need get information.

To Reproduce

I just follow Future signInWithFacebook() async { // Trigger the sign-in flow final LoginResult loginResult = await FacebookAuth.instance.login();

// Create a credential from the access token final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);

// Once signed in, return the UserCredential return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential); }

then FacebookAuth.instance.accessToken to get information to check expires

Relevant log output

No response

flutter doctor -v

[✓] Flutter (Channel stable, 3.16.0, on macOS 14.1.1 23B81 darwin-arm64, locale
    zh-Hant-TW)
    • Flutter version 3.16.0 on channel stable at
      /Users/lanticet/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (2 days ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/lanticet/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.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
      17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 119.0.6045.159

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

• No issues found!

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)

No response

darwin-morocho commented 5 months ago

Your code works but it doesn't ensure that the login with Facebook was succesful please use a code like this

import 'package:firebase_auth/firebase_auth.dart';
.
.
.
Future<UserCredential?> signInWithFacebook() async {
  final LoginResult result = await FacebookAuth.instance.login();
  if(result.status == LoginStatus.success){
    // Create a credential from the access token
    final OAuthCredential credential = FacebookAuthProvider.credential(result.accessToken!.token);
    // Once signed in, return the UserCredential
    return await FirebaseAuth.instance.signInWithCredential(credential);
  }

print(result.status);
    print(result.message)

  return null;
}

Check in your console if you are getting some error

Lanticee commented 5 months ago

I make one sample project here https://github.com/Lanticee/testfb

I do not use firebase... I just need facebook token

darwin-morocho commented 5 months ago

Have you followed this https://facebook.meedu.app/docs/5.x.x/macos ?

Lanticee commented 5 months ago

yes. i followed. and it work yestoday, after update macos or flutter today, it not work any more

I tried use await FacebookAuth.getInstance().accessToken!; it make macos app crash.

I try this FirebaseAuth auth = FirebaseAuth.instance;

User? user = FirebaseAuth.instance.currentUser;

app get crash too.

darwin-morocho commented 5 months ago

@Lanticee sorry but I am not able to reproduce the issue even using your example repo. Login with macOs was successful. The Only thing I do was add the KeySharing capability without any group and it works.

Also you can try the last version of this plugin to check if the error persists

tested on

 macOS (desktop) • macos  • darwin-arm64   • macOS 14.1.1 23B81
Lanticee commented 5 months ago

I tried sample project again.

I added key sharing flutter_secure_storage

FacebookAuth.instance.accessToken .then((value) => debugPrint(value!.token));

2023-11-18 09:19:25.930 testfb[4253:34726] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value

0 _MyHomePageState.build.. (package:testfb/main.dart:153:56)

darwin-morocho commented 5 months ago

56)

The error says that you are using ! on a null value witch is right of there is not an active session. That doesn't tell us what is the problem. Try running the example project of this repo and tell me if the error persists

Lanticee commented 5 months ago

yes, FacebookAuth.instance is not work now.

2023-11-18 09:34:09.591 testfb[5334:51532] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit

by using await FacebookAuth.instance.getUserData(); then I got


Translated Report (Full Report Below)

Process: testfb [5334] Path: /Users/USER/Documents/*/testfb.app/Contents/MacOS/testfb Identifier: com.example.fb.login.testfb Version: 1.0.0 (1) Code Type: ARM-64 (Native) Parent Process: dart [4929] Responsible: studio [4810] User ID: 501

Date/Time: 2023-11-18 09:44:51.1504 +0800 OS Version: macOS 14.1.1 (23B81) Report Version: 12 Anonymous UUID: ED2F041D-BB77-84E6-5375-644CE9FF8699

Time Awake Since Boot: 3000 seconds

System Integrity Protection: enabled

Notes: Extracting libpas PGM metadata failed.

Crashed Thread: 1 io.flutter.ui

Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000118f08f48 Exception Codes: 0x0000000000000002, 0x0000000118f08f48

Termination Reason: Namespace SIGNAL, Code 10 Bus error: 10 Terminating Process: exc handler [5334]

VM Region Info: 0x118f08f48 is in 0x118f00000-0x118f80000; bytes after start: 36680 bytes before end: 487607 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL VM_ALLOCATE 118efc000-118f00000 [ 16K] r--/r-- SM=PRV
---> VM_ALLOCATE 118f00000-118f80000 [ 512K] r--/rwx SM=PRV
VM_ALLOCATE 118f80000-119000000 [ 512K] r-x/rwx SM=PRV

Error Formulating Crash Report: Extracting libpas PGM metadata failed.

darwin-morocho commented 5 months ago

yes, FacebookAuth.instance is not work now.

2023-11-18 09:34:09.591 testfb[5334:51532] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit

by using await FacebookAuth.instance.getUserData();

then I got


Translated Report (Full Report Below)


Process: testfb [5334]

Path: /Users/USER/Documents/*/testfb.app/Contents/MacOS/testfb

Identifier: com.example.fb.login.testfb

Version: 1.0.0 (1)

Code Type: ARM-64 (Native)

Parent Process: dart [4929]

Responsible: studio [4810]

User ID: 501

Date/Time: 2023-11-18 09:44:51.1504 +0800

OS Version: macOS 14.1.1 (23B81)

Report Version: 12

Anonymous UUID: ED2F041D-BB77-84E6-5375-644CE9FF8699

Time Awake Since Boot: 3000 seconds

System Integrity Protection: enabled

Notes:

Extracting libpas PGM metadata failed.

Crashed Thread: 1 io.flutter.ui

Exception Type: EXC_BAD_ACCESS (SIGBUS)

Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000118f08f48

Exception Codes: 0x0000000000000002, 0x0000000118f08f48

Termination Reason: Namespace SIGNAL, Code 10 Bus error: 10

Terminating Process: exc handler [5334]

VM Region Info: 0x118f08f48 is in 0x118f00000-0x118f80000; bytes after start: 36680 bytes before end: 487607

  REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL

  VM_ALLOCATE                 118efc000-118f00000    [   16K] r--/r-- SM=PRV  

---> VM_ALLOCATE 118f00000-118f80000 [ 512K] r--/rwx SM=PRV

  VM_ALLOCATE                 118f80000-119000000    [  512K] r-x/rwx SM=PRV  

Error Formulating Crash Report:

Extracting libpas PGM metadata failed.

sorry but you don't provide the enough info about the problem. Plase be more clear. Also try with the example project of this plugin to check a right way to use this plugin

Lanticee commented 5 months ago

sorry, I tried to find more information, but I still do very less things. I change sample project, and found FaceBookAuth.instance.accessToken null after FacebookAuth.instance.login. I still can get accessToken from loginResult or facebookAuthCredential , just found FacebookAuth.instance.accessToken not work anymore. thx.

darwin-morocho commented 5 months ago

sorry, I tried to find more information, but I still do very less things.

I change sample project, and found FaceBookAuth.instance.accessToken null after FacebookAuth.instance.login.

I still can get accessToken from loginResult or facebookAuthCredential , just found FacebookAuth.instance.accessToken not work anymore.

thx.

Try with the lastest vesion 6.0.3

Lanticee commented 5 months ago

flutter_facebook_auth: 6.0.3

flutter: fb instance in login: null

it seems like same problem.

is it my environment get wrong?

darwin-morocho commented 5 months ago

flutter_facebook_auth: 6.0.3

flutter: fb instance in login: null

it seems like same problem.

is it my environment get wrong?

Please try with the example project inside this repo. As I said I have runned your example without any problem. I just removed the firebase auth and the groups inside the keychain capabilty due to I Just want to test the Facebook login. Also I noticed that in your login you have custom persmission keep in mind that all that permission must be enabled and authorized into your Facebook console

Lanticee commented 5 months ago

hi i remove some permissions. left permissions: const ["public_profile", "email","publish_video"],

it works now.

'pages_read_engagement', 'pages_manage_posts' make it run wrong. thx a lot