【发布时间】:2017-05-01 00:05:31
【问题描述】:
我想使用 C# 将文件上传到自动生成的 Azure 存储帐户(作为 Service Fabric 资源组的一部分,具有已知名称)。
我需要将文件作为 blob 上传以使其公开可用。
教程Get started with Azure Blob storage using .NET 使用存储在 App.config 文件中的连接字符串。 由于我要使用即将生成的存储账户,所以不能使用这种方法。
首选方法是使用用户的 AD 以获取存储帐户的密钥。
此链接:Get Storage Account Key 展示了如何通过 Rest 请求获取它,所以我想有一种方法可以使用 C# 代码来实现。
在我看来,解决方案是使用 StorageManagementClient class,它具有 StorageAccounts 属性,但我找不到使用 AzureAd 对其进行身份验证的方法。
我尝试使用AuthenticationContext.AcquireTokenAsync,并获取不同资源的令牌,例如:https://management.azure.com/,但使用令牌时,出现以下错误:
Microsoft.WindowsAzure.CloudException: AuthenticationFailed: The JWT token does not contain expected audience uri 'https://management.core.windows.net/'.
使用资源https://management.core.windows.net/ 时出现不同的错误:
Microsoft.WindowsAzure.CloudException: ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
我应该使用不同的资源,不同的方法,还是不可能?
【问题讨论】:
-
请分享您正在使用的代码。如果您以自己的身份登录以获取令牌,也请分享。最后,对于您的第二个错误,请参阅此线程:stackoverflow.com/questions/35190866/…。 HTH。
-
@Bobcat100 这个问题解决了吗?如果您对此仍有疑问,请随时告诉我。
标签: c# azure azure-storage azure-active-directory azure-storage-account