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

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

问题描述

您好,我目前正在尝试编写一个 MVC5 应用程序,该应用程序能够存储在使用 facebook 或 twitter 授权后为用户收到的令牌.

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?

所以你可以先看看这个相关的问题:如何访问脸书数据

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天全站免登陆