Friday, July 13, 2012

JavaScript SDK Now Supports Facebook Login

JavaScript SDK Now Supports Facebook Login:
Using Facebook to authenticate your users has long been a favorite feature amongst Parse developers. Today, we're happy to announce that this capability has been added to our JavaScript SDK, so your users can log into your website using their Facebook identities and your Facebook-linked user accounts can be shared between your mobile and web applications.

If you upgrade to the latest Parse JavaScript SDK, Parse.FacebookUtils has been added in order to provide support for authenticating via Facebook, and will create or log in Parse.User objects automatically. See our updated Parse Facebook documentation to see how simple we've made it.

For example, this is the code to sign up or log in a Facebook user:

Parse.FacebookUtils.logIn(null, {
  success: function(user) {
    if (!user.existed()) {
      alert("User signed up and logged in through Facebook!");
    } else {
      alert("User logged in through Facebook!");
    }
  },
  error: function(user, error) {
    alert("User cancelled the Facebook login or did not fully authorize.");
  }
});


Just as with our iOS and Android versions of Facebook support, the following happens when this code is executed:

  • The user is shown the Facebook login dialog.
  • The user authenticates via Facebook, the data is passed back to the Parse libraries.
  • Our library then saves the data to a Parse.User. If it's a new user based on the Facebook ID, then that user is created, if not, they are simply logged in.


Allowing your users to log into your Parse-powered web app using their Facebook identities is now easier than ever!

No comments:

Post a Comment