0
votes

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.

1

1 Answers

1
votes

The same approach works for Azure Blob Storage.

Azure Storage not support using AAD to authorize File storage.

Azure Storage supports using Azure Active Directory (Azure AD) to authorize requests to Blob and Queue storage.

Azure Files supports authorization with Azure AD over SMB for domain-joined VMs only. To learn about using Azure AD over SMB for Azure Files, see Overview of Azure Active Directory authorization over SMB for Azure Files.