Store and retrieve the token received for the user after authorizing with facebook or twitter

Question!

Hi I'm currently trying to write an MVC5 application that will have the ability to store the token received for the user after authorizing with facebook or twitter.

I'd like to store this in the database and not a cookie and use it on any future API requests and login attempts that the user makes so that they are not prompted to authorize with facebook or twitter each time they try to log in with that method or try to access profile info.

Looking at the membership database I can see that there is a table called AspNetTokens that isn't being used - so is there something I have missed where I can put this to use?



Answers
So if I understand your question correctly, you want to persist the facebook access token into your user database so you can use it again later?

So you can start by looking at this related question: How to access facebook data

Once you get the access token, I would actually just save this as a custom user claim for your user:

manager.AddClaim(userId, new Claim("facebookAccessToken", fbAccessToken"));

And then when you want to use it later, you can get it out from the ClaimsIdentity for the logged in user (User.Identity)

By : Hao Kung


This video can help you solving your question :)
By: admin