![](/img/trans.png)
[英]How to get Azure Storage Account Key (connectionString) using azure .net sdk or fluent API?
[英]How to get Azure Storage Account Key
我想使用C#將文件上傳到自動生成的Azure存儲帳戶(作為Service Fabric資源組的一部分,具有已知名稱)。
我需要將文件上傳為Blob,以使其可以公開使用。
使用.NET入門Azure Blob存儲教程使用了存儲在App.config文件中的連接字符串。 由於我要使用要生成的存儲帳戶,因此無法使用這種方法。
首選方法是以某種方式使用用戶的AD來獲取存儲帳戶的密鑰。
此鏈接: 獲取存儲帳戶密鑰顯示了如何通過Rest請求獲取它,因此我想有一種使用C#代碼進行存儲的方法。
在我看來,該解決方案使用的是StorageManagementClient 類 , 該類具有StorageAccounts屬性,盡管我找不到使用AzureAd對其進行身份驗證的方法。
我嘗試使用AuthenticationContext.AcquireTokenAsync ,並為不同的資源獲取令牌,例如: https://management.azure.com/
: 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.
我應該使用不同的資源,不同的方法,還是不可能?
要使用Storage Service Management REST ,我們需要將資源指定為https://management.core.windows.net/
而不是https://management.azure.com/
。 而這是使用經典存儲帳戶的操作。
https://management.azure.com/
是Azure REST服務的新終結點。 如果要處理新的存儲帳戶,則需要使用此資源。 下面是使用新的Azure REST的示例供您參考:
POST: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resrouceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/listKeys?api-version=2016-01-01
Authorization: Bearer {token}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.