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