Reputation: 73
I'm trying to call the search endpoint of the OneDrive API on a drive (i.e. 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.
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. 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
.
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.
Upvotes: 1
Views: 620
Reputation: 1874
Some important tip: client credentials flow need to register the app in the Azure Management Portal but not Applicaation Registeration Portal. Graph Explorer is mostly based on the later one, so they have different backend code now is normal. 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. Our development efforts are now concentrated on Microsoft Graph and no further enhancements are planned for Azure AD Graph API. There are a very limited number of scenarios for which Azure AD Graph API might still be appropriate; for more information, see the Microsoft Graph or the Azure AD Graph blog post in the Office Dev Center.
adal-node is not the same as Graph, so you get result in the graph explorer but not the NodeJS product. We suggest you to use the latest Graph API.
Official docs: https://learn.microsoft.com/en-us/javascript/api/overview/azure/activedirectory?view=azure-node-latest
Upvotes: 0