FB user authentication in my site

22 views
Skip to first unread message

A Kast

unread,
Mar 12, 2019, 5:36:59 PM3/12/19
to RestFB
Hi 

I'm trying to figure out whether this library supports my use case: I need to provide a way for users to authenticate themselves via their FB login to my website.

I saw that FacebookClient has the getLoginDialogUrl() method.  If I understand correctly, I think this might be used to generate a link which the user could click to browse to the FB login page, and then be redirected back to my site.  But I'm still not clear how my site would actually grok their details after they've logged in.  Presumably FB would have set some kind of cookie in their browser indicating that they've logged in, but how do I on the server side now get that information?  Which relevant RestFB APIs should I be using?

Thanks

Norbert Bartels

unread,
Mar 14, 2019, 6:04:06 PM3/14/19
to RestFB
Hi,

yes you can use the getLoginDialogUrl() to generate a URL for the login dialog. There your user has to enter his/hers Facebook credentials because afterwards Facebook sends the user to an URL on your server. In this URL you'll find the information. RestFB provides the obtainUserAccessToken and this method returns an access token for this user. 


This is an example code with an embedded browser, but if you replace the success URL constant with your server url you can simply use parts of the code to create your own login flow. It is a bit tricky on the first sight.

Hope this helps

Norbert
Reply all
Reply to author
Forward
0 new messages