【Azure Developer】中国区Azure环境中查看用户账号是否可用(accountEnabled)的操作步骤

问题描述

在 21V(中国运营的 Microsoft 云,世纪互联)环境中,需要通过 Microsoft Graph API获取某个用户的 accountEnabled(账号启用/禁用)状态。

由于国家云与全球版在 令牌颁发端点、Graph 服务根域名、以及 权限作用域(scope) 上存在差异,很多"全球版"教程在中国区直接套用会出现 401/403 或取不到该属性(返回 null)的问题。

本文聚焦"在中国区Azure环境中,正确查询指定用户的 accountEnabled 值"的可操作步骤

问题解答

第一步:连接中国区Azure环境并获取Token

az cloud set --name AzureChinaCloud

az login

az account get-access-token --resource 'https://microsoftgraph.chinacloudapi.cn/'

第二步:使用发送REST API的客户端发送GET请求获取用户的User ID

GET https://microsoftgraph.chinacloudapi.cn/v1.0/users?$filter=userPrincipalName eq 'your login user account , the format is xxx@xxx.xxx.onmschina.cn'

第一步中获取的Token作为Authorization值,请求返回的格式如下:

复制代码
{
  "@odata.context": "https://microsoftgraph.chinacloudapi.cn/v1.0/$metadata#users",
  "value": [
    {
      "businessPhones": [],
      "displayName": "your name",
      "givenName": null,
      "jobTitle": null,
      "mail": "xxx@xxx.xxx.onmschina.cn",
      "mobilePhone": null,
      "officeLocation": null,
      "preferredLanguage": null,
      "surname": null,
      "userPrincipalName": "xxx@xxx.xxx.onmschina.cn",
      "id": "xxx-xxx-xxx-xxx-xxx"
    }
  ]
}

第三步:获取user的account状态

GET https://microsoftgraph.chinacloudapi.cn/v1.0/users/\<xxx-xxx-xxx-xxx-xxx>?$select=displayName,accountEnabled

第一步中获取的Token作为Authorization值,第二步中的ID值替换URL中的<xxx-xxx-xxx-xxx-xxx>。

执行请求,返回的结果如下:

复制代码
{
  "@odata.context": "https://microsoftgraph.chinacloudapi.cn/v1.0/$metadata#users(displayName,accountEnabled)/$entity",
  "displayName": "user name",
  "accountEnabled": true
}

返回结果中的accountEnabled就是最终所需要的结果!

参考资料


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关推荐
Smart-佀1 天前
涨薪秘技:智能家居中的BLE协议与实现
网络·arm开发·嵌入式硬件·microsoft
Ares-Wang1 天前
flask 》》celery 异步任务
flask
KivenMitnick2 天前
CialloVOL 1.2:便捷好用的轻量化内存取证分析平台
windows·python·安全·网络安全·flask·系统安全·安全威胁分析
Y敲键盘的地方2 天前
第3章 对话即编程
人工智能·microsoft
薛定猫AI2 天前
【深度解析】Claude Code 本地代理架构:用 Free Cloud Code 降低 Agentic Coding 成本
microsoft·架构
Ares-Wang2 天前
flask 》》内置HTMLParser
后端·python·flask
武藤一雄2 天前
WPF中逻辑树(Logical Tree)与可视化树(Visual Tree)到底是什么
microsoft·c#·.net·wpf·.netcore
软泡芙2 天前
【.NET】创建一个ai聊天应用
人工智能·flask·.net
love530love2 天前
Clink 在 VS 2022 Developer Command Prompt 中的配置与路径精简调校
人工智能·windows·microsoft·clink
m0_466525293 天前
东软智行与腾讯云达成战略合作 共筑AI智能座舱新生态
人工智能·microsoft·腾讯云