Search code examples
javascriptnode.jsfacebookfacebook-graph-apiparse-server

Facebook login for mobile clients with Node express backend


I'm using parse-server (on heroku) as the backend for a mobile app.

Facebook login/signup will be an option for users.

What's the best workflow?

  1. I was thinking the mobile client could login to FB and pass the token to the express app. The express app could grab the data we need from FB and create/login the Parse user.

Is there a module where I can plug in the auth token and ping FB for the profile picture, DOB, or whatever else I need?

  1. Parse JS SDK has a facebookUtils API. Can I create a route that the mobile apps can hit in a browser to login to FB? If so how can I get the data I need from FB once they've logged in?

Any insight and sample code would be MUCH appreciated.

Thanks!


Solution

  • I have been using the facebook APIs for social login in my App, i used the first approach you mention i.e.

    I was thinking the mobile client could login to FB and pass the token to the express app. The express app could grab the data we need from FB and create/login the Parse user.

    I use two FB APIs, one for authenticating the app and the other for authenticating the user.

    The mobile client fetch the acces token form facebook and passes to the backend express APP. the two APIs used are:-

    1. For authenticating the App

      https://graph.facebook.com/app/?access_token=

    2. For authenticating the user

      https://graph.facebook.com/me?fields=id,email,name,gender,picture&access_token="

    p.s. you can select the parameter like name or email according to your need.

    For authenticating the app, when you hit the API, you will get a json containing the FB_APP_id, which is unique and can be compared with the one provided by fb while you create your project on fb.

    So far this approach is ok as my app is live and working fine.