Parse+Facebook - how do you login Parse.User from a FBUser?

Continuing the discussion from Facebook login + Parse:

I can use the OpenFb library (see above) to connect an FB user to a current Parse.User (i.e. Parse.User.current()) or to a new Parse.User. It works fine.

But how do you handle the case when existing user tries to sign-in using FB Connect? I can do an FB login and then call Parse.Query to find the matching Parse.User record. But I can’t actually do a Parse.User.logIn() because I don’t have the actual password.

Is there a workaround here? Or do you just re-direct the user to sign-in with their Parse username/password?

You can use the Parse REST API to login a Parse.User from the Facebook id & accessToken. This method doesn’t seem to be available in the Parse JDK

see: https://parse.com/docs/rest/guide#users-signing-up-and-logging-in

return $cordovaFacebook.login(["public_profile", "email", "user_friends"])
       .then(function (success) {
            // save access_token
           $localStorage.accessToken = success.authResponse.accessToken;
           $localStorage.userID = success.authResponse.userID;
           $localStorage.expiresIn = success.authResponse.expiresIn;

           console.log("Login Success" + JSON.stringify(success));

           var expDate = new Date(new Date().getTime() + $localStorage.expiresIn * 1000).toISOString();

           return Parse.FacebookUtils.logIn({
                 id: $localStorage.userID,
                 access_token: $localStorage.accessToken,
                 expiration_date: expDate
           });
      }).then(function (_parseResult) {
          $localStorage.parseData = _parseResult;
      ).function(_error) {
           console.log(JSON.stringify(_error));
      };
  })

Basically login the normal way through Facebook and pass the authData through to Parse.com

See more details here - http://www.clearlyinnovative.com/ionic-framework-facebook-login-with-parse/

1 Like