6

I am working on a Flutter app and need to include the Facebook and Google login options in our app login page. I am not using Firebase and working on the MySQL database for storing and retrieving user's data.

I am looking for Adding the FB and Google authentication in my flutter app without the Firebase. I was not able to find any article for this. Everywhere it is always using the Firebase.

After following a tutorial, I have registered my app in FB Developer console, but I am not sure what will be put in the 'OAuth redirect URL' field there.

Currently, I am using xampp server and nodeJS for server side handling. Below is the code which I am calling on my button click. I am using plugin for Facebook authentication(Please let me know if this plugin is specifically for Firebase).

void initiateFacebookLogin() async {
    var facebookLogin = FacebookLogin();
    facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;
    print("Inside fb login");
    var facebookLoginResult = await facebookLogin
        .logInWithReadPermissions(['email', 'public_profile']);
    switch (facebookLoginResult.status) {
      case FacebookLoginStatus.error:
        print("Error");
        onLoginStatusChanged(false);
        break;
      case FacebookLoginStatus.cancelledByUser:
        print("CancelledByUser");
        onLoginStatusChanged(false);
        break;
      case FacebookLoginStatus.loggedIn:
        print("LoggedIn");

        var graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email,picture.height(200)&access_token=${facebookLoginResult.accessToken.token}');

        var profile = json.decode(graphResponse.body);
        print(profile.toString());

        onLoginStatusChanged(true, profileData: profile);
        break;
    }
  }
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Rajan Mishra
  • 61
  • 1
  • 3
  • The Valid OAuth Redirect URIs field is relevant for login on the web only. If you are creating a native mobile app, it has no relevance. – misorude Jan 09 '19 at 12:00
  • 2
    The pub package `google_sign_in` works without Firebase: https://pub.dartlang.org/packages/google_sign_in – Marcel Jan 09 '19 at 15:06

1 Answers1

0

As mentioned in the comments, both Facebook and Google Sign in can work without Firebase. There's a sample code for Flutter google_sign_in package that you can try here.

Omatt
  • 8,564
  • 2
  • 42
  • 144