Skip to content

Login with Facebook

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 register with and experience the application.

In order to integrate Facebook login with Backendless, client application must use the Facebook SDK to authenticate the user and then makes a Backendless API call to link the Facebook identity to a BackendlessUser instance.

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 via "property mapping". There may be multiple mapping, each must reference  a Facebook user field and a name of a Backendless property. Once a 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.

Backendless Configuration

A Backendless application (the server side) 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.

Integration API

The API provides a way to "exchange" Facebook access token for Backendless user object which represents the corresponding Facebook user. Before using the API, application must perform login to Facebook using its SDK. The integration process consists of the following steps:

Method

POST

URL

https://api.backendless.com/<application-id>/<REST-api-key>/users/social/facebook/sdk/login 

where:

Argument                Description
<application-id> the ID of your application generated upon its creation. You can obtain the value in the Manage > App Settings section of the Backendless Console.
<REST-api-key> REST API key of your application. You can obtain the value in the Manage > App Settings section of the Backendless Console.

Request Body

{  
  "accessToken" : value,  
  "fieldsMapping" :  
   {  
      "first_name" : "FirstName",  
      "last_name" : "LastName"  
   }  
}

where:

Argument                Description
accessToken Access token received from the Facebook SDK authentication request. This is a required value.
fieldsMapping an optional 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. The Facebook keys correspond to the Facebook Graph API keys. Social properties will be copied to the Backendless user properties and should be updated manually in case of their change.

Response Body

a JSON representation of a BackendlessUser object.

Example

Login request with field mappings:

curl \  
-H 'Content-Type: application/json' \  
-X POST \  
-d'{"accessToken" : "CAANVVCKZA1Y0BAA4Z....", "fieldsMapping":{"first_name":"First", "last_name":"Last", "email":"email", "name":"name"}}' \  
-v https://api.backendless.com/application-id/REST-api-key/users/social/facebook/sdk/login

Login response:

{"lastLogin":1454524395923,"created":1454524396000,"ownerId":null,"__meta":"{\"relationRemovalIds\":{},  
\"selectedProperties\":[\"__updated__meta\",\"Last\",\"created\",\"name\",\"___class\",\"First\",  
\"ownerId\",\"updated\",\"email\",\"objectId\",\"__meta\"],\"relatedObjects\":{}}","user-registered":  
true,"Last":"Bond","name":"James Bond","___class":"Users","First":"Bond","user-token":  
"E6D5DD4F-4F0D-4D99-FF3D-CCB8DFFB3400","updated":null,"email":"james@mi6.gov.uk"  
"objectId":"3CBA1744-0487-320F-FF4D-E69B3F6D8500"}