使用c#中的身份验证令牌获取用户详细信息
本文关键字:获取 用户 详细信息 令牌 身份验证 使用 | 更新日期: 2023-09-27 18:02:20
我正在使用servicestack,在客户端,我有facebook身份验证,这将提供一个accesstoken后登录
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
验证完成后,cookie值为setup fbsr_Appid
,其中包含验证令牌
当用户向servicestack发出请求时,我将能够从上下文中的cookie值中获取此身份验证令牌。那么现在,我如何使用这个令牌获得用户的用户ID/电子邮件ID呢?
目前我能够使用下面的url获取访问令牌的过期时间
https://graph.facebook.com/oauth/access_token_info?client_id=APPID&access_token=xxxxxxxxx
返回如下格式的响应
{
access_token: "xxxxxxxx",
token_type: "bearer",
expires_in: 5560
}
最后我想到了一个办法
var details = string.Format("https://graph.facebook.com/me?access_token={0}", token);
这是给出如下格式的响应
{
id: "344657773358323",
email: "zz@gmail.com",
first_name: "xxxxxx",
gender: "male",
last_name: "xxxxxx",
link: "https://www.facebook.com/app_scoped_user_id/xxxxx/",
locale: "en_US",
name: "xxxx xxxx",
timezone: 5.5,
updated_time: "xx-xx-xx:07:xx+0000",
verified: true
}