Share via

Microsoft Graph Error : me request is only valid with delegated authentication flow

Anonymous
2024-11-05T10:35:42+00:00

Hi ,

I have a azure function (Timer) that gets files in a one drive folder but I'm encountering an error.

Error Message : me request is only valid with delegated authentication flow.

Microsoft Graph Version : 5.61.0

Code:

 private static async Task<GraphServiceClient> GetAuthenticatedGraphClient()

{

       var tenantId= Environment.GetEnvironmentVariable("TenantId");

       var clientId= Environment.GetEnvironmentVariable("ClientId");

       var clientSecret= Environment.GetEnvironmentVariable("ClientSecret");

       var scopes= new[] { "https://graph.microsoft.com/.default" };

       var options= new ClientSecretCredentialOptions

       {

           AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,

       };

       var clientSecretCredential= new ClientSecretCredential(

           tenantId, clientId, clientSecret, options);

       var graphClient= new GraphServiceClient(clientSecretCredential, scopes);

       return graphClient;

}

 public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer)

 {

     _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

     var txtSourceFolder= Environment.GetEnvironmentVariable("txtSourceFolder");

     var graphClient= await GetAuthenticatedGraphClient();

     var driveID= await graphClient.Me.Drive.GetAsync();

     var driveItem= graphClient.Drives[driveID.Id]

                             .Items["root"]

                             .ItemWithPath(txtSourceFolder)

                             .Content

                             .GetAsync();

     if (myTimer.ScheduleStatus is not null)

     {

         _logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");

     }

}

Microsoft 365 and Office | OneDrive | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-11-05T12:44:38+00:00

    Hi ACL09,

    Thanks for posting in the community. We are happy to help you.

    We would love to help you with your query, however, since it is related to Microsoft Graph, and we have a specific channel Microsoft Q&A Community coping with questions about Microsoft Graph, I recommend you post a new thread (click "Ask a question" and add the tags Microsoft Graph, and Microsoft Entra ID) there for expert help.

    Sorry that our category may have limited resources on checking on your concern further.

    Thanks for your understanding.

    George | Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments