2017-04-08 218 views
0

我正在使用此包https://www.nuget.org/packages/Microsoft.Identity.Client 来验证用户,auth工作正常,问题是,我想使用登录后得到的令牌来获取用户姓名和电子邮件(因为我不仅需要访问收件箱,联系人和日历,还需要使用电子邮件将用户链接到电子邮件)。 问题是,当我得到的令牌,我得到一个很长的字符串作为userId(我猜加密)。有什么方法可以使用这个软件包来获取电子邮件吗?使用Microsoft.Identity.Client获取用户名和电子邮件

这是我得到的令牌后面的部分

public SessionTokenCache(string userId, HttpContextBase httpContext) 
    { 
     this.userId = userId; 
     cacheId = userId + "_TokenCache"; 
     this.httpContext = httpContext; 
     BeforeAccess = BeforeAccessNotification; 
     AfterAccess = AfterAccessNotification; 
     Load(); 
    } 

这是我跟 https://dev.outlook.com/restapi/tutorial/dotnet

回答

0

一旦你有一个道理,也许你可以使用图形API来获取详细教程为登录用户?结果是Json可以用来提取你想要的位。

 public static async Task<string> GetUserData(string token) 
    { 
     //get data from API 
     HttpClient client = new HttpClient(); 
     HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me"); 
     message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", token); 
     HttpResponseMessage response = await client.SendAsync(message); 
     string responseString = await response.Content.ReadAsStringAsync(); 
     if (response.IsSuccessStatusCode) 
      return responseString; 
     else 
      return null; 
    } 
相关问题