I am writing a mobile application using O-Auth "connect with Facebook" to:
1) Let Facebook deal with the authentication 2) Not force my users to register to another website 3) Get Facebook information
I implemented a Facebook server login (in JAVA):
https://developers.facebook.com/docs/howtos/login/server-side-login/
I do not understand how I can maintain a user session when a user connected to-facebook.
Here is a flow from end to end, please correct me if I am wrong.
1) The user logs into my server (Android APP using WebView) 2) The server redirect the user to Facebook (with client_id, redirect_url, state and permissions) 3) The user is now facing Facebook login dialog. 3.1) If the user deny: Facebook calls the redirect_url and notify the server that there was an error. (Flow Ends here) 3.2) If the user accept: Facebook calls the redirect_url (my server) with the state i've set (for CSRF protection) and a code. 4) The server contacts Facebook and send it the app_id, redirect_url, client_secret and code and in return, facebook calls the redirect_url with a valid token. This token allows the server to issue facebook API calls on behalf of the user.
So far, everything is working fine. Now for the main question - Session Management.
Now that I have received the token, I need to find out which user it belongs to, so I can grab data from my database or create a new record (in the case of a new user).
1) What identifier should I use to identify the user on my db server? (Do I need to call the Facebook API to extract basic information and from this extract the email address and / or unique identifier?
2) Once I received this unique identifier, how do I contact the user again? In step 2, the server redirected it to Facebook, which means that it opened a new connection to Facebook, and it is no longer connected to the server. How do I set it up as a cookie now that itβs gone? <- * This part is confusing to me. *
3) At what point do I need to set the SESSION identifier (cookie) in the userβs request, so the next time he contacts me, I will find out who it is.
I think stack overflows are the best example to illustrate my problem. I clicked the "Connect with facebook" button, and suddenly I became a user when the stack overflowed without registering. How does stack overflow know how to pull out the questions that I already asked? How did that define me? And at what point in the chain that I described did she set a cookie at my request?
thank you for your time