如何通过API调用从id_token获取用户配置文件

问题描述:

我有一个应用程序使用的API,应用程序向我发送了已经过身份验证的用户或Google帐户的id_token。如何通过API调用从id_token获取用户配置文件

如何在ASP.net中向API API调用API调用(而不是Java脚本调用)以获取用户配置文件信息(如名称),以便将用户保存在应用程序的数据库中。

我已经有一个谷歌项目与客户端ID和客户端的秘密。

所以我找到了一种方法,虽然asp.net API获取我想要的用户信息。

using (var client = new System.Net.WebClient()) 
    { 
     var uri = new Uri("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + ACCESSTOKENFROMLOGGININ + "&access_type=offline"); 
     var response = client.DownloadString(uri); 
    } 

you response will have these fields 
{ 
"issued_to": "", 
"audience": "", 
"user_id": "", 
"scope": "", 
"expires_in": 756, 
"email": "", 
"verified_email": true, 
"access_type": "online" 
} 

Then you could make another call to get more personal information 

var userInfoUri = new Uri("https://www.googleapis.com/oauth2/v2/userinfo"); 
        var userInfoClient = new System.Net.WebClient(); 
        client.Headers.Add("Authorization", "Bearer " + YOUACCESSToken); 

and you will receive an object like this 

{ 
"id": "", 
"name": "", 
"given_name": "", 
"family_name": "", 
"link": "", 
"picture": "",`enter code here` 
"locale": "en" 
}