1

我想使用Azure SDK中的WebSiteManagementClient,但我在第一個障礙 - 創建客戶端時墮落了。我已經創建了一個Active Directory應用程序,遵循David Murray提供的說明,並允許我創建一個TokenCredential,我成功用它來創建SQLManagementClient的SQL數據庫。如何創建一個可以訪問WebSiteManagementClient的Azure憑證?

ClientCredential cc = new ClientCredential("{myApplicationId}", "{myAzurePassword}"); 
var context = new AuthenticationContext("https://login.windows.net/{myTennantId}"); 
var result = context.AcquireToken("https://management.azure.com/", cc); 
if (result == null) 
    throw new InvalidOperationException("Failed to obtain the JWT token"); 
TokenCloudCredentials CloudCred = new TokenCloudCredentials(subscriptionId, result.AccessToken); 
var sqlClient = new SqlManagementClient(CloudCred); 
... 
// and this can be used to create databases in resource groups 

WebSiteManagementClient似乎需要一組不同的參數。首先它需要一個ServiceClientCredential,然後是一些DelegatingHandlers。我在哪裏可以獲得ServiceClientCredential?什麼是委託處理程序。我用這個例子找了一個博客,但沒有成功。我非常感謝任何指針。 謝謝

回答

1

繼續我的搜索,我發現並回答了類似問題here,但這次訪問ComputeManagementClient。在測試瞭解決方案後,我意識到我非常接近。我只需要創建一個result.AccessToken憑證,而不是與SubscriptionID,如下

ClientCredential cc = new ClientCredential("{myApplicationId}", "{myAzurePassword}"); 
var context = new AuthenticationContext("https://login.windows.net/{myTennantId}"); 
var result = context.AcquireToken("https://management.azure.com/", cc); 
if (result == null) 
    throw new InvalidOperationException("Failed to obtain the JWT token"); 
TokenCredentials Cred = new TokenCredentials(result.AccessToken); 
var sqlClient = new SqlManagementClient(CloudCred); 
... 
// and this can be used to create databases in resource groups 

我要感謝諾亞斯塔爾,誰提供的答案有

+0

當我做你建議我在這裏嘗試使用WebsiteManagmentClient(創建時)會得到PlatformNotSupportedException。我能找到的每一個樣本都需要證書,但爲什麼這是必需的,這是毫無意義的。想法? –

相關問題