首页 文章

MS Graph API和DriveItem搜索不使用客户端凭据流

提问于
浏览
1

我正在尝试在驱动器上调用OneDrive API的搜索 endpoints (即 https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='mysearchterm') . 这在Graph Explorer上工作正常,但是,我没有在同一驱动器上获得客户端凭据流的任何搜索结果 .

我的应用程序注册具有API文档中提到的所有必需的应用程序权限( Files.Read.AllFiles.ReadWrite.AllSites.Read.AllSites.ReadWrite.All ),并且读取驱动器,driveitems,下载驱动器项目都可以正常工作 . 一件事不起作用的是搜索驱动器项目 . 我只是得到一个空阵列,没有错误;

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)","value":[]}

我正在使用 adal-nodeacquireTokenWithClientCredentials .

var adal = require("adal-node");

const TENANT = "{tenant-name-here}.onmicrosoft.com";
const CLIENT_ID = "{Application-id-here}";
const CLIENT_SECRET = "{Application-key-here}";

function getToken() {
  return new Promise((resolve, reject) => {
    const authContext = new adal.AuthenticationContext(
      `https://login.microsoftonline.com/${TENANT}`
    );

    authContext.acquireTokenWithClientCredentials(
      GRAPH_URL,
      CLIENT_ID,
      CLIENT_SECRET,
      (err, tokenRes) => {
        if (err) {
          reject(err);
        }
        resolve(tokenRes.accessToken);
      }
    );
  });
}

我正在搜索的驱动器是一个SharePoint文档库 .

1 回答

  • 0

    Some important tip :客户端凭据流需要在Azure Management Portal中注册应用程序,但不能在Applicaation Registeration Portal中注册 . Graph Explorer主要基于后者,所以他们现在有不同的后端代码是正常的 . 也许他们会在未来做同样的逻辑 .

    我们强烈建议您使用Microsoft Graph而不是Azure AD Graph API来访问Azure Active Directory资源 . 我们的开发工作现在集中在Microsoft Graph上,并且Azure AD Graph API没有进一步的增强功能 . Azure AD Graph API可能仍然适用的场景非常有限;有关详细信息,请参阅Office开发人员中心中的Microsoft Graph或Azure AD Graph博客文章 .

    adal-node与Graph不同,因此您可以在graph explorer中获得结果,但不能获得NodeJS产品 . 我们建议您使用最新的Graph API .

    官方文件:https://docs.microsoft.com/en-us/javascript/api/overview/azure/activedirectory?view=azure-node-latest

相关问题