Login with Facebook

Top  Previous  Next

Backendless integrates with Facebook to support user authentication and login into a Backendless application with a Facebook account. Using the integration application developer can provide a way to skip the application registration step and allow users to use their Facebook identity to enter and experience the application. Backendless provides two ways to handle Facebook logins:

Easy Facebook Login - The Facebook SDK is not required on the client. The client application makes a Backendless API call to initiate the login and the user authenticates in a Facebook popup window.
Login with Facebook SDK - The client application uses the Facebook SDK to authenticate the user and then delegates to a Backendless API call to link the Facebook identity to a BackendlessUser instance.

Both approaches - Easy Login and Login with SDK, rely on the concepts and a configuration change described below.

Property Mapping

Backendless user objects may have their own set of user properties. As a result, when a user logs in using their Facebook account, their Facebook Graph API user fields are mapped to the Backendless user properties. A single mapping references a Facebook user field and the name of a Backendless property. The mapping is a required as it dictates which Facebook properties must be used when creating a corresponding Backendless user account. Once the user is authenticated, Backendless obtains the field values from the Facebook user graph object and populates the mapped properties in the BackendlessUser object. For the very first login, Backendless also creates the user in its internal system.

Permissions

The client application can request the permissions from the user to access additional user information or perform various actions. Requested permissions is a collection of string objects passed as an argument in the Backendless API call to login a Facebook user.

The Facebook permissions can be found at https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference.

Backendless Configuration

Backendless backend must be configured with Facebook's application App ID and secret key. See the "Social Settings" chapter of the user guide (the Manage section) for detailed instructions for configuring Backendless with Facebook.

Easy Facebook Login

Backendless client SDK and the server-side implementation follows the following process to support the easy login option:

1.The client application initiates the Facebook login sequence by calling a method from the Backendless SDK.
2.The invocation results in a UI dialog where the user enters their Facebook credentials and submits the form.
3.The form submission is sent to Facebook.
4.Upon successful login, Facebook executes a redirect to the Backendless servers.
5.Backendless receives the user information from Facebook and returns it back to the client.

The diagram below illustrates the process:

backendless-facebook-login

API

Method:

Backendless.UserService.loginWithFacebook(facebookFieldsMapping, permissions, callback, container); 

where:

facebookFieldsMapping - a mapping between the Facebook fields and Backendless user properties. Keys must be the names of the Facebook fields, values - the names of the Backendless properties

callback- an object which receives either a return value or an error from the server. The class must implement Backendless.Async instance
permissions- a collection of the Facebook permissions/scopes, to which the application requests access.
container- container block for facebook authorization activity.

 

Login With Facebook SDK

As the name suggests this option uses the Facebook SDK to handle the login to a Backendless application. The result of the operation is an instance of the BackendlessUser class which contains the property values initialized from the Facebook user account. Using the Facebook SDK with Backendless consists of the following steps:

Configure the environment with the Facebook SDK. Complete instructions are available at: https://developers.facebook.com/docs/javascript/quickstart/v2.2
Configure Backendless backend with the Facebook App ID/API Key.
Use the API call described below.

Backendless.UserService.loginWithFacebookSdk(facebookFieldsMapping, callback);

where:

facebookFieldsMapping - a mapping between the Facebook fields and Backendless user properties. Keys must be the names of the Facebook fields, values - the names of the Backendless properties

callback- an object which receives either a return value or an error from the server. The class must implement Backendless.Async instance.

 


Please let us know how we can improve the documentation by leaving a comment. All technical questions should be posted to the Backendless Support forum. We do not respond to the technical questions on the documentation pages.: