Mobile Backend as a Service (MBaaS) Blog

Simplifying Secure User Login: Facebook Authentication for Your Apps

facebook login app

Do you ever worry about how painful it is for users to create unique usernames and remember passwords just for your app? Strong passwords are almost impossible to remember, shared passwords create a huge vulnerability, and weak passwords are of no good use. Plus, many users are turned off by the effort it takes to provide basic profile information for an app.

As a developer, you have a lot to think about when it comes to building an app: the front end, the user experience, the design, etc. Worrying about users forgetting their app usernames and passwords – and therefore losing access to your app – takes away valuable time that could be spent on these elements. Instead of worrying about getting users to provide you some basic information about themselves, you could be focusing on your user interface. Rather than having to choose between living with a hinderance to the adoption of your app or compromising the security of your users, you can plan how to monetize your app, and actually get a good sleep.

 

Over the last few months, we received many requests asking for Facebook integration with Kinvey users. Our latest release makes it very easy for you to do exactly that – allow your users to login to your app using their Facebook accounts.

You can easily have users establish an explicit identity using Facebook sign-on and continue to use Kinvey to build your app backend without any other changes. This feature is now available as part of our REST API, through our JavaScript library, and using our iOS SDK.

This is our first feature towards offering social integration. Our goal is to bring you features that enable broader and deeper integration into the core experience offered by Facebook and other social networks.

JavaScript library

Login and authentication through Facebook is done by using Facebook’s JavaScript SDK. Typically, the exchange looks as follows:

To integrate Facebook with Kinvey, only a few additional lines of code are required:

 

Internally, the JavaScript library will check whether the token already exists. If so, it will login and return the user linked to that token. Otherwise, a new user is created for you. As an example, we’ve integrated Facebook with the Pay It Forward demo app for browsers as well as PhoneGap. For further reference, please consult the JavaScript Developer’s Guide.

iOS library

Our iOS SDK is designed to work with the Facebook SDK library 3.0. The Facebook SDK will take care of requesting the user credentials and returning a valid token to the Kinvey SDK. You can download the Facebook SDK for iOS here.

Once you have a valid Facebook token, using it to log the user into Kinvey is a simple call to loginWithFacebookAccessToken:.

 

We’ve integrated Facebook login with the KinveyGram sample application. This example shows how to login a user either with a username and password or with the Facebook token. 

For further reference, consult the iOS developer’s guide and download version 1.7 of the library.

Android library

Our Android SDK is designed to work with the Facebook SDK library. The Facebook SDK will take care of requesting the user credentials and returning a valid token to the Kinvey SDK.

You can download the Facebook SDK for Android here.

Once you have a valid Facebook token, using it to log the user in to Kinvey is a simple call to loginWithFacebookAccessToken

Download version 1.3.2 of the library here.

 

REST API

Our REST API has been extended in the same way as our libraries above.

You can register a Facebook account using an OAuth access token while creating a Kinvey user, you can remove that registration at any time, and you can login using OAuth access tokens against the same user from multiple devices.

FBSetupLogin

You will find examples of API calls in our documentation.

FBLogoutDataPurge

When you use Facebook sign-on, we also retrieve and store some basic account information in the User collection like name and gender that will help you personalize the app experience to your users. The exact list is specified in our documentation. You can use the console data browser to access this information as well.

You asked for it, we built it! Sign up for Kinvey to start using this exciting feature and take a tour of the Kinvey platform too. You can also reach us with any questions, concerns, and feedback by emailing support@kinvey.com.

let's talk about this computer

Starting a new mobile project? Check out our App Cost Estimator for a price quote.

comments powered by Disqus