I am working on an Azure Function to download a file from a SharePoint Online Library.
I am using the Microsoft Graph to achieve this. I am using the ClientSecretCredential for authentication.
Microsoft.Graph Version: 5.37.0
.Net Version: 6.0
Note: The below line of code working fine, and I am able to get the Document details like URL, Created Time .......
var test = await graphClient.Drives["*****"].Items["*******"].ListItem.GetAsync();
Note: The below line of code failing with an exception "The proxy tunnel request to proxy 'http://****/' failed with status code '407'"
But the same code is working If I used in the console application.
var proxyAddress = "http://******.****.***:*****/";
var handler = new HttpClientHandler
{
Proxy = new WebProxy(proxyAddress),
};
var options = new ClientSecretCredentialOptions()
{
Transport = new HttpClientTransport(handler),
};
// Values from app registration
var clientId = "";
var tenantId = "";
var clientSecret = "";
var tokenCredential = new ClientSecretCredential(
tenantId,
clientId,
clientSecret,
options);
var authProvider = new AzureIdentityAuthenticationProvider(tokenCredential);
var httpClient = GraphClientFactory.Create(proxy: new WebProxy(proxyAddress));
var graphClient = new GraphServiceClient(httpClient, authProvider);
var test = await graphClient.Drives["*****"].Items["*******"].ListItem.GetAsync();
var stream = await graphClient.Drives["*******"].Items["********"].Content.GetAsync();