Button to retrieve FB Access Token

Hi everyone,
I am using appfoundation for my project, but i guess my question is more general than its implementation.

Basically, once a user is logged in, i would like to give him the possibility of retrieving a FB access token and save it on his Database entry.

Facebook, basically, works like this:

  1. You fire the request by connecting to something like https://www.facebook.com/dialog/oauth?client_id=*Client id*&redirect_uri=A redirect URL&scope=requested access

  2. The redirect URL process the reply from FB, which contains a code, and calls https://graph.facebook.com/oauth/access_token?client_id=*client id&redirect_uri=Redirect URL&client_secret=Client Secret&code=The code sent by FB

  3. If everything’s correct, the second redirect will receive the access token by FB.

Now, i’d like to save this access token, and associate it with the user who fired the first request. Can anybody suggest how to achieve this? Cos i lose the session that caused the request when facebook sends the replies…

Thanks a lot!