I am trying to connect to Azure File Share but it is throwing Authentication Error.
AzureServiceTokenProvider tokenProvider = new AzureServiceTokenProvider();
string accessToken = await tokenProvider.GetAccessTokenAsync("https://storage.azure.com/", "");
log.LogInformation(accessToken);
TokenCredential tokenCredential = new TokenCredential(accessToken);
StorageCredentials storageCredentials = new StorageCredentials(tokenCredential);
Uri fileAddress = new Uri("File URI");
CloudFile sourceFile = new CloudFile(fileAddress, storageCredentials);
log.LogInformation(await sourceFile.DownloadTextAsync());
Error: Make sure the value of Authorization header is formed correctly including the signature.
The same approach works for Azure Blob Storage.
I have assigned Storage File Data SMB Share Contributor role to Managed Identity of my Azure Function.
Let me know if you need more info.
Thanks for the help.