How can I perform firebase authentication with facebook in flutter

2,210

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']);
Share:
2,210
Dmitry Garazhny
Author by

Dmitry Garazhny

Updated on December 11, 2022

Comments

  • Dmitry Garazhny
    Dmitry Garazhny over 1 year

    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