Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Facebook Login in Native Desktop App

I'm writing a VC++ app and I would like to allow users to login via Facebook. Looking through the documentation, it looks like they only support php on servers, JavaScript, and native mobile clients.

Right now what I'm thinking of doing is to open a browser window in the app, have the user authenticate, and then grab the auth token to do native app calls.

The other thing I was thinking of is having the user enter the Facebook username and password into my app and then using that directly, but I'm not sure if that's allowed.

How do I authenticate a desktop app with Facebook?

like image 330
Jason Avatar asked Oct 21 '22 16:10

Jason


1 Answers

Right now what I'm thinking of doing is to open a browser window in the app, have the user authenticate, and then grab the auth token to do native app calls.

Actually you are on the right track: Facebook provides you with a so called "Manual Flow".

So this is how you authenticate your users with Facebook in your app in three steps:

Step 1

When the user should login to Facebook, open the embedded browser and point to this url:

https://www.facebook.com/dialog/oauth?client_id={app-id}&display=popup&redirect_uri=https://www.facebook.com/connect/login_success.html

Three things to note here:

  1. Of course, you need to replace {app-id} with your application's id.
  2. The redirect_uri must be set to https://www.facebook.com/connect/login_success.html when using a desktop application (that's your case).
  3. You can also specify additional parameters, for example if you need to request extended permissions from the user (publish_actions, etc.). See the full list of optional parameters for more information.

Step 2

Make sure you have enabled the following switches in your app's advanced settings:

Native or desktop app and embedded app secretOAuth settings

For security reasons, you should enter https://www.facebook.com/connect/login_success.html under "Valid OAuth redirect URIs", but it worked for me without explicitly setting this.

Step 3

Now the redirection by the Facebook servers should navigate the browser window to the redirect uri from above. It will also include the access token in the uri's fragment as follows:

https://www.facebook.com/connect/login_success.html#access_token=ACCESS_TOKEN...

Use the ACCESS_TOKEN in order to make any subsequent calls to the Facebook API - et voilà!

like image 150
markus Avatar answered Oct 27 '22 11:10

markus