简体   繁体   English

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

[英]MS Graph API and DriveItem search not working with client credentials flow

I'm trying to call the search endpoint of the OneDrive API on a drive (ie https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='mysearchterm') . This works fine on the Graph Explorer, however, I'm not getting any search results with the client credentials flow on the same drive. 我试图在驱动器上调用OneDrive API的搜索端点(即https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='mysearchterm') 。在Graph Explorer上工作正常,但是,在相同驱动器上没有客户端凭据流的任何搜索结果。

My app registration has all the required application permissions mentioned in the API documentation ( Files.Read.All , Files.ReadWrite.All , Sites.Read.All , Sites.ReadWrite.All ) and reading drives, driveitems, downloading drive items is all working fine. 我的应用程序注册具有API文档中提到的所有必需的应用程序权限( Files.Read.AllFiles.ReadWrite.AllSites.Read.AllSites.ReadWrite.All ),并且读取驱动器,驱动器项,下载驱动器项都是工作正常。 The one thing that is not working, is searching on drive items. 不起作用的一件事是搜索驱动器项目。 I'm just getting an empty array back, no errors; 我只是得到一个空数组,没有错误;

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

I'm using adal-node with acquireTokenWithClientCredentials . 我使用的是阿达尔节点acquireTokenWithClientCredentials

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);
      }
    );
  });
}

The drive I'm searching on is a SharePoint document library. 我正在搜索的驱动器是SharePoint文档库。

Some important tip : client credentials flow need to register the app in the Azure Management Portal but not Applicaation Registeration Portal . 一些重要提示 :客户端凭据流需要在Azure管理门户中注册应用程序,而无需在应用程序注册门户中注册 Graph Explorer is mostly based on the later one, so they have different backend code now is normal. Graph Explorer主要基于后一种,因此它们具有不同的后端代码现在很正常。 Maybe they will do the same logic in furture. 也许他们将来会做同样的逻辑。

We strongly recommend that you use Microsoft Graph instead of Azure AD Graph API to access Azure Active Directory resources. 强烈建议您使用Microsoft Graph代替Azure AD Graph API来访问Azure Active Directory资源。 Our development efforts are now concentrated on Microsoft Graph and no further enhancements are planned for Azure AD Graph API. 现在,我们的开发工作集中在Microsoft Graph上,并且没有计划对Azure AD Graph API进行进一步的增强。 There are a very limited number of scenarios for which Azure AD Graph API might still be appropriate; 在少数情况下,Azure AD Graph API可能仍然适用; for more information, see the Microsoft Graph or the Azure AD Graph blog post in the Office Dev Center. 有关更多信息,请参见Office开发人员中心中的Microsoft Graph或Azure AD Graph博客文章。

adal-node is not the same as Graph, so you get result in the graph explorer but not the NodeJS product. adal-node与Graph不同,因此您可以在图资源管理器中获得结果,但不能在NodeJS产品中得到结果。 We suggest you to use the latest Graph API. 我们建议您使用最新的Graph API。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有Simple-OAuth2和客户端凭据流的Microsoft Graph API - Microsoft Graph API with Simple-OAuth2 and Client Credentials Flow 使用客户端凭据流访问Office365 API - Accessing Office365 API with Client Credentials Flow Spotify WebAPI授权 - 客户端凭据流错误invalid_client - Spotify WebAPI authorization - client credentials flow error invalid_client passport.js 是否支持“客户端凭据流”? - Does passport.js support 'Client Credentials Flow'? 使用Graph API的通配符搜索人员 - Wildcard search people with Graph API Spotify API 客户端凭据返回“错误”:“无效客户端” - Spotify API Client Credentials returns "error": "invalid_client" 如何在节点 oidc-provider 中为 client_credentials 流定义 JWT 令牌模式 - How to define JWT token mode for client_credentials flow in node oidc-provider 在哪里可以找到 Google API 客户端的凭据。json? - Where to find credentials.json for Google API client? Dropbox令牌API在Node.js中返回“缺少客户端凭据” - Dropbox token API returns “Missing client credentials” in Node.js 谷歌云存储节点客户端 - 凭据未按预期工作 - google cloud storage node client - credentials not working as expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM