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

使用Graph API获取用户自定义安全属性返回null的问题求助

排查Graph API获取用户自定义安全属性返回null的问题

问题详情

调用接口 https://graph.microsoft.com/v1.0/me?$select=customSecurityAttributes,返回结果中customSecurityAttributes字段为null。当前访问令牌已包含以下权限:

CustomSecAttributeAssignment.Read.All
CustomSecAttributeDefinition.Read.All
Directory.Read.All
email
offline_access
openid
Presence.Read.All
Presence.ReadWrite
profile
TeamworkTag.Read
User.Read
User.Read.All
User.ReadBasic.All

返回结果示例:

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(customSecurityAttributes)/$entity",
    "id": "aa76f0c6-d534-46ea-8dc0-48c917567dce",
    "customSecurityAttributes": null
}

排查与解决步骤

  • 确认用户是否已分配自定义安全属性
    这是最常见的原因:登录Azure门户,进入「Azure Active Directory」→「自定义安全属性」→「属性分配」,检查该用户是否有已分配的属性记录。也可调用GET https://graph.microsoft.com/v1.0/users/{user-id}/customSecurityAttributes(替换{user-id}为实际用户ID)验证,若仍返回null,说明用户未被分配任何自定义安全属性。

  • 检查权限的授予状态与类型

    • 确认CustomSecAttributeAssignment.Read.All和CustomSecAttributeDefinition.Read.All权限已被管理员授予:委托权限需完成管理员同意流程,应用权限需直接分配给应用。可在Azure门户「企业应用」→ 你的应用 →「权限」中查看权限状态。
    • 若使用用户上下文调用(me),委托权限可生效,但需确保权限已通过管理员同意。
  • 统一API版本
    返回结果的@odata.context指向beta版本,但你调用的是v1.0端点。虽然customSecurityAttributes在v1.0已正式可用,仍建议统一使用v1.0端点,避免版本不一致导致的兼容性问题。

  • 检查属性的可见性配置
    进入Azure门户「自定义安全属性」→「属性集」,查看对应属性集的「可见性」设置,确保当前用户的角色或应用权限有权限查看该属性。部分属性可能被配置为仅特定角色可见。

  • 验证访问令牌的实际权限
    使用令牌解析工具解析你的访问令牌,确认:

    • scp(委托权限)或roles(应用权限)字段中确实包含所需的自定义安全属性读取权限。
    • 令牌的aud(受众)为https://graph.microsoft.com,确保令牌是针对Graph API颁发的。

内容的提问来源于stack exchange,提问作者Swapnil Chowkekar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 09:20:10