我曾嘗試下面的代碼來創建在Azure中的新存儲帳戶:天青 - 編程創建存儲帳戶
獲取令牌(成功 - 我收到一個令牌):
var cc = new ClientCredential("clientId", "clientSecret");
var context = new AuthenticationContext("https://login.windows.net/subscription");
var result = context.AcquireTokenAsync("https://management.azure.com/", cc);
創建雲存儲憑據:
var credential = new TokenCloudCredentials("subscription", token);
創建雲存儲賬戶(失敗):
using (var storageClient = new StorageManagementClient(credentials))
{
await storageClient.StorageAccounts.CreateAsync(new StorageAccountCreateParameters
{
Label = "samplestorageaccount",
Location = LocationNames.NorthEurope,
Name = "myteststorage",
AccountType = "RA-GRS"
});
}
錯誤:
ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
我不知道這是否是那些誤導性消息中的一個,或者如果我錯誤地配置在Azure中的東西嗎?
請看看這個回答你的問題:https://stackoverflow.com/questions/35190866/error-making-azure-management-library-api-call-when-authenticating-with-azure-ac/ 35194706#35194706。 –
@GauravMantri非常感謝 - 該鏈接提供了獲取正確標識符的見解 –