You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Microsoft Graph SDK如何获取用户的authentication/emailmethods值?

解决Azure AD用户信息查询中authentication/emailMethods返回null的问题

问题原因

authentication是Microsoft Graph中用户实体的导航属性,而非直接的属性字段,仅通过$select无法加载其关联数据,必须使用$expand来展开该导航属性,同时指定要获取的子属性emailMethods。

修改后的代码

将原请求配置改为同时使用Expand指定展开authentication/emailMethods:

var users = await graphServiceClient.Users.GetAsync((requestConfiguration) =>
{
    requestConfiguration.QueryParameters.Select = new string[] 
    { 
        "displayName", 
        "id", 
        "givenName", 
        "surName", 
        "streetAddress", 
        "city", 
        "state", 
        "postalCode", 
        "country", 
        "userPrincipalName"
    };
    // 展开authentication导航属性并加载emailMethods子数据
    requestConfiguration.QueryParameters.Expand = new string[] { "authentication/emailMethods" };
});

额外说明

  1. 权限验证:确认已配置UserAuthenticationMethod.Read.All(应用权限)或UserAuthenticationMethod.Read(委派权限),且权限已完成授予并生效。
  2. 性能优化:若仅需获取单个用户的邮箱验证方法,建议使用单个用户端点(graphServiceClient.Users["{userId}"].Authentication.EmailMethods.GetAsync()),批量展开导航属性会增加请求负载,单个查询更高效。

内容的提问来源于stack exchange,提问作者wonderful world

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:22:44