When implementing Facebook login using oAuth2 (the Javascript version), I receive an access token back from the Facebook auth server. So far so good.
The problem I have is that I want to implement a RESTful back end, where the user needs to authenticate on every request for accessing a back end resource, using a server generated token. What happens is that when using the standard login on my website (email + password), this token gets generated on the server by my own application and is then sent to the front end where it is stored (all transactions happen over https).
So I thought about using the access token that I receive from Facebook to store it in my back end, if the user wants to log in using Facebook. This way, every RESTful request to the back end could be checked against this token.
The problem however, is that the back end cannot check if the token received from the client is a valid Facebook access token (this is a Javascript client application, heavily relying on Ajax for all server communication). Even though I can write Javascript to only send the access token to the back end on successful authentication with the FB server, this process is not reliable as the Javascript is not protected.
My question is:
How can I safely store a token in my back end, after the user authenticated with Facebook?
Please note that I am creating a Javascript application using Backbone.
