azure-active-directory - MSGraph token 错误: "Application (...) was not found in the directory"

标签 azure-active-directory microsoft-graph-api onedrive

我正在尝试在 PHP 中实现 Microsoft Graph for OneDrive 访问。我要去 this documentation

我已在 https://apps.dev.microsoft.com/ 注册了我的应用,并获得了应用 ID 和 key 。

现在,对于 token 流,我发出以下链接:

$LogonLink = 
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize?".
 http_build_query(array(
    'client_id' => $MSGraphAppID,
    'response_type' => 'code',
    'redirect_uri' => 'http://www.example.com/ongraph.php',
    'response_mode' => 'query',
    'scope' => 'offline_access Files.ReadWrite'));

登录和权限 UI 按预期工作,我的应用程序的名称和图标出现。这样App ID就被识别了。现在,ongraph.php 通过代码获得控制权,我发出以下 POST:

$cu = curl_init('https://login.microsoftonline.com/common/oauth2/v2.0/token');
$Form = array(
    'client_id' => $MSGraphAppID,
    'scope' => 'offline_access Files.ReadWrite',
    'code' => $_GET['Code'],
    'redirect_uri' => 'http://www.example.com/ongraph.php',
    'grant_type' => 'authorization_code',
    'client_secret' => $MSGraphSecret
);
curl_setopt_array($cu, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query($Form)));

$r = curl_exec($cu);

我收到错误 400 和以下响应:

{
    "error": "unauthorized_client",
    "error_description": "AADSTS70001: Application with identifier '0000000048205436' was not found in the directory 9188040d-6c67-4c5b-b112-36a304b66dad\r\nTrace ID: b0f7cba6-42b3-4f37-8438-5e8566ba1300\r\nCorrelation ID: ca51b601-86cb-4801-a330-354ffd3c715f\r\nTimestamp: 2017-11-08 17:12:33Z",
    "error_codes": [70001],
    "timestamp": "2017-11-08 17:12:33Z",
    "trace_id": "b0f7cba6-42b3-4f37-8438-5e8566ba1300",
    "correlation_id": "ca51b601-86cb-4801-a330-354ffd3c715f"
}

请问我在这里缺少什么?我尝试创建一个全新的应用程序注册,结果相同。

编辑:这就是应用程序注册网站的样子:

Registration UI screenshot

最佳答案

这里的问题是您已将应用程序注册为 Live SDK application :

Live SDK Application Registration

对于 v2 端点(和 Microsoft Graph),您需要将其注册为 Converged application :

Converged Application

https://apps.dev.microsoft.com站点处理这两种应用程序类型。

关于azure-active-directory - MSGraph token 错误: "Application (...) was not found in the directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47185926/

相关文章:

azure - 邀请 Azure 应用程序加入租户

azure - 如何使用用户名和电子邮件进行注册,并使用 Azure AD B2C 本地帐户使用用户名或电子邮件登录?

powershell - 通过 Graph 更新 AzureAD/O365 UPN

c# - 如何将 Onedrive<Item> 的内容写入本地文件

onedrive - 是否可以使用 Windows 8 Phone 模拟器登录 Microsoft 帐户?

c# - 使用 Azure DevOps 获取个人访问 token

没有域名的 Azure AD 登录页面

javascript - 在 TypeScript 中初始化 Azure 应用程序客户端

angular - 如何从 Angular 获取 OneDrive API 的访问 token

java - 使用 Microsoft Graph API 仅按标题搜索 OneDrive 文件