NetTalk Central

Author Topic: This is how to add a "Login with Facebook" button  (Read 2661 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1846
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
This is how to add a "Login with Facebook" button
« on: July 25, 2017, 04:09:39 PM »
Hi, this post is to share my experience doing a "Login with Facebook" button with NetTalk. Hope this helps.

1- Declare a facebook app, you will get an app id and a secret string from facebook, you need to set the page that will receive the facebook result.
https://developers.facebook.com/apps

2- In your login page add a button with the following URL
'https://www.facebook.com/dialog/oauth?client_id=xxxAPPIDxxx&redirect_uri=http://www.yourdomain.com/yourPage&scope=public_profile,email'

If the user cancell, then facebook call your page with:
error=access_denied&error_code=200&error_description=Permissions%20error&error_reason=user_denied#_=_

If the user accepts your app login, with:
code=AQASDKwq39m1Zj5n-Pfu2JY16LjtPWQamJTNsXUecW97gVF8HhUl8VMono0KMc10sT8QVRQAbhK04CtyfyOSXZ0nHEGpiZdxuMQ5ZVPggZOEbbMuHva4GXAko_bSeWlVh7hfgoJX8AcLG_dgdpyBFRw3dY6j1rXpqTAu4wSCatzKGE13-f63zZOSv6_JWmdtBNvpsBBUfCixq5feEnMAGCmn-Dcxrpxx3s7n8mc_gjWnuGiky5hLN3EKnjTZCXUamHkdCvoCywxGF9jp4tsiJxusKsveHAQkkxB-TAPLw859i0ZEFv-8pNsCuBEjs0dtT9ufKc7EE9O2S-4RpXw84zqg#_=_

3- With this code, made a get to:
https://graph.facebook.com/oauth/access_token?client_id=xxxAPPIDxxx&redirect_uri=http://www.doctoranyplace.com/TodayPage&client_secret=xxxxxxSECRETSTRINGxxxx&code=AQCISg-sQ_mj1TxXlaPD3PUgxmeU--h_UpVg1m6E3HOa9w5MtTGYqsJ6IeprzWzqJW5k20b4yaaURJniutMXqETnKRGvarE_lBGaaip3rbYh4yRdgAMlK-KQvrKJiZhSg_uR9SnUR5NWO5nAc31ofG-R8a9VX72_s8p40Ry89I2g5-zEg48UoCPSglsn4mAyucvYa0HamHw2S9h1qv9Q3zqwV9zipo8YxZzZgKLN5RLmzYhxGVVsZhy7EcE01CcQEZ7s9C2rLd0uh0gM9T333B5wl2hqiaNOF86YlVcIKAhJ5FwaLlj2_2sU9e_Mavdu5CY#_=_&scope=public_profile,email

You coudl see the scopes here: https://developers.facebook.com/docs/facebook-login/permissions

This get response a json indicating a token like:
{"access_token":"EAABkUc14GucBAGpQAOyZC5ZCOx894gvtcINs7l8Gczhcy5q5CyfyJvIqAiRVuUzUp51vU8jZBsqQugni9B8wpcEZBXUZA6sbPonwgAf1XlKhwUz1fq5zBUvsBw1veRu6U3MkrHD6QImc6LuiNvAU3mKnUUCzUJddYbcEEqYkeBwZDZD","token_type":"bearer","expires_in":5181177}

4- With this token make a get to:
https://graph.facebook.com/me?access_token=EAABkUc14GucBAGpQAOyZC5ZCOx894gvtcINs7l8Gczhcy5q5CyfyJvIqAiRVuUzUp51vU8jZBsqQugni9B8wpcEZBXUZA6sbPonwgAf1XlKhwUz1fq5zBUvsBw1veRu6U3MkrHD6QImc6LuiNvAU3mKnUUCzUJddYbcEEqYkeBwZDZD

And you willl get a json response like:
{
   "name": "Alberto Molinari",
   "id": "14151491985xxxxx"
}

The ID is what you have to manage at your own as the User Identifier.
Depending on the facebook user you will get or not the email.

Regards


--
*Alberto Michelis*
ARMi software solutions www.armisoftware.com <http://www.armisoftware.com>
-----------
Regards
Alberto

urayoan

  • Full Member
  • ***
  • Posts: 222
    • View Profile
    • AZ Rock Radio
Re: This is how to add a "Login with Facebook" button
« Reply #1 on: July 26, 2017, 11:05:52 AM »
Thanks for share Alberto!