与Facebook或Twitter授权后存储和检索,为用户收到的令牌 [英] Store and retrieve the token received for the user after authorizing with facebook or twitter

查看:135
本文介绍了与Facebook或Twitter授权后存储和检索,为用户收到的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写,将要为用户收到该邮件存储与Facebook或Twitter授权后才能的MVC5应用程序。

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.

我想这个存储在数据库中,而不是一个cookie,并用它在任何未来的API请求,登录尝试,用户使,使他们不提示与Facebook授权或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.

综观会员数据库中,我可以看到,有一个叫做AspNetTokens表没有被使用 - 所以是有什么我错过了,我可以把这个使用

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?

推荐答案

所以,如果我正确地理解你的问题,你要facebook的访问令牌持续到你的用户数据库,这样你就可以再次使用它以后呢?

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?

所以,你可以通过查看此相关的问题开始:<一href=\"http://stackoverflow.com/questions/18942196/how-to-access-facebook-private-information-by-using-asp-net-identity-owin\">How访问Facebook数据

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"));

然后当你以后要使用它,你可以从ClaimsIdentity把它弄出来的登录用户(User.Identity)

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

这篇关于与Facebook或Twitter授权后存储和检索,为用户收到的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆