Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I perform firebase authentication with facebook in flutter [duplicate]

I'm trying to add firebase and facebook authentication in my app. Facebook auth is already done:

final facebookLogin = FacebookLogin();
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=name,first_name,last_name,email&access_token=$token');
    Map<String, dynamic> user = jsonDecode(graphResponse.body);
    // _onGetFacebookUser(user);

I don't know how to perform firebase authentication with facebook result.

I've already watched this answer, but it doesn't help, there is only facebook login code example. I've found this article, but there is no method signInWithFacebook

like image 456
Dmitry Garazhny Avatar asked Jan 26 '23 08:01

Dmitry Garazhny


1 Answers

You have to use credential

final result = await facebookLogin.logInWithReadPermissions(['email']);

switch (result.status) {
  case FacebookLoginStatus.loggedIn:
    final token = result.accessToken.token;
    AuthCredential fbCredential = FacebookAuthProvider.getCredential(accessToken: token);
    FirebaseAuth.instance.signInWithCredential(credential).then((FirebaseUser user) {
      // do something...
    });
...

UPD:

It worked fine for flutter_facebook_login version 2.0.1 For now for version 3.0.0 there is method 'login':

final result = await facebookLogin.logIn(['email']);
like image 175
Andrey Turkovsky Avatar answered Feb 08 '23 23:02

Andrey Turkovsky