You need to enable JavaScript to run this app. Azure AD守护应用调用Graph用户手机认证方法端点报Access Denied问题排查
优惠活动
大模型
产品
解决方案
定价
更多

Azure AD守护应用调用Graph用户手机认证方法端点报Access Denied问题排查

Azure守护应用调用Graph手机认证方法端点权限被拒问题

问题场景

在Azure AD中创建守护类应用,计划通过Python MSAL库调用 GET https://graph.microsoft.com/beta/users/{id | UPN}/authentication/phoneMethods 端点获取用户的手机认证方法信息。
接口调用后返回如下错误:

{
  "error": {
    "code": "accessDenied",
    "message": "Request Authorization failed",
    "innerError": {
      "message": "Request Authorization failed",
      "date": "2020-11-19T19:26:28",
      "request-id": "11975e07-ee6b-4bd2-9a74-7c175c5da560",
      "client-request-id": "11975e07-ee6b-4bd2-9a74-7c175c5da560"
    }
  }
}

前期排查验证动作

  • 已在应用注册页面配置目标接口所需的应用程序权限,包含 UserAuthenticationMethod.Read.All、UserAuthenticationMethod.ReadWrite.All
  • 同一应用可正常调用通用用户信息端点,例如 GET https://graph.microsoft.com/beta/users/{id | UPN}
  • 排除代码层逻辑问题:将相同请求换成curl、Postman手动发起,仍然返回完全一致的错误,初步判断问题根源在访问令牌的权限维度

现有实现代码

import json
import logging

import requests
import msal


config = {
    "authority": "https://login.microsoftonline.com/TENANT_NAME",
    "client_id": "APP_ID",
    "scope": ["https://graph.microsoft.com/.default"],
    "secret": "APP_SECRET",
    "endpoint": "https://graph.microsoft.com/beta/users/{USER_ID}/authentication/phoneMethods"
}

app = msal.ConfidentialClientApplication(
    config["client_id"], authority=config["authority"],
    client_credential=config["secret"],
    )

result = None
result = app.acquire_token_silent(config["scope"], account=None)

if not result:
    logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
    result = app.acquire_token_for_client(scopes=config["scope"])

if "access_token" in result:
    graph_data = requests.get(
        config["endpoint"],
        headers={'Authorization': 'Bearer ' + result['access_token']}, ).json()
    print("Graph API call result: ")
    print(json.dumps(graph_data, indent=2))
else:
    print(result.get("error"))
    print(result.get("error_description"))
    print(result.get("correlation_id"))

常见触发原因与排查思路

  • 核对应用权限是否完成租户管理员全局同意:仅在应用注册页添加权限列表,不代表权限对服务主体生效,必须由租户管理员为该应用授予所有已配置的应用权限,未同意的权限不会出现在访问令牌的角色声明中,就会出现普通用户接口正常、敏感认证类接口被拒的现象。
  • 解码获取到的访问令牌,核对roles字段的实际内容:通过公开的令牌解码工具查看令牌中携带的权限项,确认是否真的存在UserAuthenticationMethod.Read.All对应的权限值,避免因为权限授权延迟、缓存未刷新导致令牌权限缺失。
  • 确认端点的权限要求匹配:该beta版手机认证方法端点属于高敏感操作接口,历史版本中曾要求服务主体同时具备全局读者类的角色分配,仅靠应用权限可能无法满足接口的授权校验逻辑。
  • 排查租户条件访问策略:该类涉及用户认证方法的操作属于高风险范围,租户默认的条件访问策略可能会拦截未在允许列表中的应用发起的请求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.16 19:36:03