0

我想使用C#將文件上載到自動生成的Azure存儲帳戶(作爲Service Fabric資源組的一部分,名稱已知)。如何獲取Azure存儲帳戶密鑰

我需要將文件上傳爲blob以允許它公開。

本教程Get started with Azure Blob storage using .NET使用存儲在App.config文件中的連接字符串。 由於我想使用待生成的存儲帳戶,因此我無法使用這種方法。

優先方法是以某種方式使用用戶的AD以獲取存儲帳戶的密鑰。

此鏈接:Get Storage Account Key顯示如何使用Rest請求獲取它,所以我想有一種方法可以使用C#代碼來完成它。

在我看來,解決方案是使用StorageManagementClient class,它具有StorageAccounts屬性,但我找不到使用AzureAd對其進行身份驗證的方法。

我試着用AuthenticationContext.AcquireTokenAsync,並aquiring爲diffenent資源令牌,例如: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. 

是否有不同的資源我應該使用,不同的方法,或者它不可能?

+0

請分享您正在使用的代碼。如果您以自己的身份登錄以獲取令牌,也可以共享。最後,爲您的第二個錯誤,請參閱此線程:http://stackoverflow.com/questions/35190866/error-making-azure-management-library-api-call-when-authenticating-with-azure-ac/35194706#35194706 。 HTH。 –

+0

@ Bobcat100已解決此問題?如果您仍然有問題,請隨時告訴我。 –

回答

2

要使用Storage Service Management REST,我們需要指定資源爲https://management.core.windows.net/而不是https://management.azure.com/。這是使用經典的存儲帳戶。

https://management.azure.com/Azure REST service的新端點。如果您想處理新的存儲帳戶,則需要使用此資源。以下是使用新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} 
相關問題