【问题标题】:How to get email from identityref如何从 identityref 获取电子邮件
【发布时间】:2021-02-22 09:46:09
【问题描述】:
我看过UserHttpClient、ProfileHttpClient 和GraphHttpClient。
当我有来自工作项(“AssignedTo”字段)的IdentityRef 时,我无法弄清楚如何从其中的任何一个中检索电子邮件地址。
之前我认为uniquename 字段始终是电子邮件地址的位置,但前提安装似乎并非如此?
【问题讨论】:
标签:
c#
azure-devops
azure-devops-rest-api
【解决方案1】:
我终于明白了。
identityRef 包含一个名为Descriptor 的字段,它对应于ProfileHttpClient (Rest api) 中的“用户描述符”。
因此,要获得电子邮件,必须执行以下操作:
public static Task<string> GetEmailAddress(this VssConnection connection, SubjectDescriptor descriptor)
{
var client = connection.GetClient<GraphHttpClient>();
var user = await client.GetUserAsync(descriptor.ToString());
return user?.MailAddress;
}
// .. and in your code (where assignedTo is an IdentityRef).
var email = await connection.GetEmailAddress(assignedTo.Descriptor);
更新
这在 Azure DevOps Server 上不起作用,因为 Graph 在其上不可用。所以问题仍然存在。
(将此作为云版本的答案)