Search code examples
azure-active-directorymicrosoft-graph-apionedrive

One Drive REST API - Current authenticated context is not valid for this request


I'm trying to build a background service that authenticates with One Drive via REST Calls. For now, I've registered a test application in the portal from my own email id and able to get a token. But when I try to see all files from my drive using this end point - https://graph.microsoft.com/v1.0/me/drive/root/children, I receive a BAD request - Current authenticated context is not valid for this request response. I wouldn't need any administrative consent because there will be only user from this background service at all times. The article I referred is here - https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service#3-get-administrator-consent

Appreciate any help.


Solution

  • I guess the problem is that you are making a request using application permissions (client_credentials flow) - where there is no signed-in user context. Your request is to /me, and /me is basically an alias for the signed-in user . You should use GET /users/{idOrUserPrincipalName}/drive instead .

    To use application permissions or delegate permissions are based on your requirement . You may refer to authentication Scenarios for Azure AD for more details . Or you should explain more about your current scenario .