C# 使用Microsoft.Identity.Client获取用户名和电子邮件

C# 使用Microsoft.Identity.Client获取用户名和电子邮件,c#,asp.net-mvc,email,C#,Asp.net Mvc,Email,我正在使用这个软件包 为了验证用户身份,auth工作正常,问题是,我想使用登录后获得的令牌来获取用户名和电子邮件(因为我不仅需要访问收件箱、联系人和日历;还需要使用电子邮件将用户链接到rol)。 问题是,当我得到令牌时,我得到一个长字符串作为userId(我猜是加密的)。我有没有办法使用此软件包获取电子邮件? 这是我取回代币的地方 public SessionTokenCache(string userId, HttpContextBase httpContext) {

我正在使用这个软件包 为了验证用户身份,auth工作正常,问题是,我想使用登录后获得的令牌来获取用户名和电子邮件(因为我不仅需要访问收件箱、联系人和日历;还需要使用电子邮件将用户链接到rol)。 问题是,当我得到令牌时,我得到一个长字符串作为userId(我猜是加密的)。我有没有办法使用此软件包获取电子邮件?

这是我取回代币的地方

public SessionTokenCache(string userId, HttpContextBase httpContext)
    {
        this.userId = userId;
        cacheId = userId + "_TokenCache";
        this.httpContext = httpContext;
        BeforeAccess = BeforeAccessNotification;
        AfterAccess = AfterAccessNotification;
        Load();
    }
这是我遵循的教程

拥有令牌后,您是否可以使用Graph 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;
    }
公共静态异步任务GetUserData(字符串令牌)
{
//从API获取数据
HttpClient=新的HttpClient();
HttpRequestMessage=新的HttpRequestMessage(HttpMethod.Get)https://graph.microsoft.com/v1.0/me");
message.Headers.Authorization=new System.Net.Http.Headers.AuthenticationHeaderValue(“承载者”,令牌);
HttpResponseMessage response=等待客户端.SendAsync(消息);
string responseString=wait response.Content.ReadAsStringAsync();
if(响应。IsSuccessStatusCode)
回报率;
其他的
返回null;
}