Facebook Javascript SDK Authentication Persistence? - facebook

I'm using the following Facebook Client SDK inorder to authenticate a user without a page refresh (works great)
http://developers.facebook.com/docs/reference/javascript/
The problem I have is I want to store some data along with that user in a local database. SO if the user authenticates himself it would pull back his given data.
I'v seen access tokens but that isn't a permant link to the user. What exactly do I need to check server side as well to guarantee the user and what would I need to store in my DB (account table)?

You could get the user facebook id and check each time if he is present in the database or he is a new one.

Related

How to store temporary data that has no logged in users

I am working on an app using Laravel that retrieves posts from facebook pages (using fb IPA) then make some operations on them, this tool can be used with no login or creating an account, and my question is:
how and to store the temporary data I get from the API since I don't have users knowing this app can be used by many people at the same time?
I guess you could solve this in several ways. I'm not quite sure what you do the get the data.
You'll need something unique to relate to the data. In case you login to the API using OAuth you could request the user profile of the user (example here using the Facebook SDK) and grab the user id or the email address. In case you do not login then you could use something like the session id.

Storing Facebook login using PHP

I'm using the Facebook PHP API to allow logins into my website. I am also allowing people to login/register using a built in form in my software incase they don't want to use their Facebook account.
I have this all working fine, my only issue is how do I attach the Facebook account to their account in my MySQL Database?
So for example Joe Bloggs wants to create an account on my website. Rather than filling in a form, he decides to login via Facebook. He does so. After he logs in via Facebook, it returns him to a page on my website where he can fill in the rest of his account details. It then saves his account and he is free to sue the website.
My issue is after he logs in with Facebook, creates and saves his account in the MySQL Database, how do I link his Facebook account and his account in my database?
When you login with Facebook, it returns a STATE, CODE and I can also retrieve an ACCCESS TOKEN using the API. However every time I login, these codes change. I thought there might be one code returned that I can use to store in the MySQL Database so all I have to do is match one of the codes to the database.
But I can't seem to do this. Am I coming at this all wrong?
Hope I'm making sense.
My issue is after he logs in with Facebook, creates and saves his account in the MySQL Database, how do I link his Facebook account and his account in my database?
Just store facebook user id in your table.
When you login with Facebook, it returns a STATE, CODE and I can also retrieve an ACCCESS TOKEN using the API. However every time I login, these codes change. I thought there might be one code returned that I can use to store in the MySQL Database so all I have to do is match one of the codes to the database.
You don't need to persist them ever. Only facebook user id is the identifier you need to identify user
Store their FaceBook UserID as an optional field in your user table to link their unique FaceBook UserID to a user in your application.
https://developers.facebook.com/docs/reference/php/facebook-getUser/

facebook: how to store and retrieve access_token on server side?

I am trying to understand, how facebook authentication works and how the flow should look like. I am working with Google App Engine and I have managed to obtain first the code and then access token. Using it I can for example retrieve user's friends list. This is all cool.
However, how can I store this access_token? I wan to allow my user to access different pages in my facebook app and I will need this access token on those pages. How can I store it and how can I retrieve it? Or maybe no matter which page user accesses I first need to get the code and then access token and only then can I perform some operations on his behalf?
I don't want to use javascript sdk for now. Is it possible to do it all from server side?
how can I store this access_token? I
wan to allow my user to access
different pages in my facebook app and
I will need this access token on those
pages. How can I store it and how can
I retrieve it?
just store the access_token in the datastore.
https://github.com/facebook/python-sdk/blob/master/examples/appengine/example.py
line 50.
It is from the facebook python sdk.
https://github.com/facebook/python-sdk/
If you don't want to use javascript sdk, you need to see this document. It has all details for facebook Oauth.
http://developers.facebook.com/docs/authentication/
While facebook redirect your user to your page assigned by redirect_uri. It will give your the code (A_CODE_GENERATED_BY_SERVER), then your server can get the user's access_token/facebook id with server side facebook api + code. Then you can login your user (set the session/cookie) and do whatever you want.

Facebook Graph API server side authentication (no client side)

So I have stored the "access_token" and marked it as "offline_access". All that is fine. Now, what I am trying to do is: I want a PHP page to "refresh"/be executed every minute, and then use that token that I stored (which I want to change at anytime manually, say from a field in the database) and then change the status of the user. Say I have the tokens for 3 of my facebook accounts.
I know how to post and all that, but when I try it without a session, it is telling me I need to create a session to do it. However, this is server-side. I don't know how to do the session without seeing the "login" button of Facebook on the server side.
How to do this? Any thoughts on how to make my PHP page, when executed, create a new Facebook object from the Facebook PHP class, and then plug in the whatever Access Token and UID maybe, and then post to the wall of the user?
Thanks!
Answered here:
Facebook offline access step-by-step

Login system like Disqus for Twitter and Facebook

How do they manage to get user to login to Twitter / Facebook through Javascript so smoothly?
I am trying to replicate it for the web app. Basically, the user only needs to add a javascript snippet to their site to kickstart but I am clueless as to how to integrate facebook and twitter connect seamlessly.
Do they store access tokens after successfully authenticating a user?
Short answer is yes, they store access tokens after successfully authenticating a user.
After you try facebook and twitter apis, you'll see that, they both returns ids for every user who succesfully logged-in through your application. You can then simply add those ids pairing with the platform they logged in to your database. You can then use that data to track users easily.
You need to
Create applications on both platforms
Have pages for each provider to check if user performed a succesful login
Check if user is a newcomer and add that user to your database if so.
Set a session or cookie variable of user's local id in your own application or do whatever you are normally doing to track if a user logged-in as that user is your local user.