在 Azure 管理门户中,您只能看到 Active Directory 中用户的对象 ID。
但在 C# 代码中,如果您拥有该用户的 JWT 令牌,您可以像下面这样对其进行解码并从中获取您想要的任何属性:
var token = new JwtSecurityToken(jwtToken);
var oid = token.Claims.FirstOrDefault(m=>m.Type == "oid").Value;
var sub = token.Claims.FirstOrDefault(m => m.Type == "sub").Value;
但是,如果您没有用户的用户名密码,则无法从 AAD 为他们获取 JWT 令牌。
或者,您可以使用 AAD Graph API 从 AAD 获取更详细的用户信息,但即使 Azure Graph API 在响应中也不会有“SUB”,而只有 Object Id:
https://msdn.microsoft.com/en-us/library/azure/dn151678.aspx
这是使用 AAD Graph 的 GET 用户调用的响应:
{
"odata.metadata": "https://graph.windows.net/contoso.onmicrosoft.com/$metadata#directoryObjects/Microsoft.WindowsAzure.ActiveDirectory.User/@Element",
"odata.type": "Microsoft.WindowsAzure.ActiveDirectory.User",
"objectType": "User",
"objectId": "4e971521-101a-4311-94f4-0917d7218b4e",
"accountEnabled": true,
"assignedLicenses": [],
"assignedPlans": [],
"city": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Alex Wu",
"facsimileTelephoneNumber": null,
"givenName": null,
"jobTitle": null,
"lastDirSyncTime": null,
"mail": null,
"mailNickname": "AlexW",
"mobile": null,
"otherMails": [],
"passwordPolicies": null,
"passwordProfile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"preferredLanguage": null,
"provisionedPlans": [],
"provisioningErrors": [],
"proxyAddresses": [],
"state": null,
"streetAddress": null,
"surname": null,
"telephoneNumber": null,
"usageLocation": null,
"userPrincipalName": "Alex@contoso.onmicrosoft.com"
}