我使用下面的代碼,試圖在Azure中的Active Directory編程方式註冊的應用程序:如何使用流暢API創建Azure AD應用程序?
var application = azure.ActiveDirectoryApplications.Define(applicationName)
.WithSignOnUrl(url)
.WithIdentifierUrl(url)
.WithAvailableToOtherTenants(false)
.DefinePasswordCredential(id)
.WithPasswordValue(secret)
.Attach()
.Create();
凡azure
是Microsoft.Azure.Management.Fluent.Azure
一個實例。
當我運行上述操作來創建Azure Active Directory應用程序時,將引發Microsoft.Azure.Management.Fluent.Azure
異常,並顯示消息Operation returned an invalid status code 'Forbidden'
。其他Azure資源(如資源組和應用服務)的創建工作得很好。
看着異常的詳細信息,我可以看到的請求作出了以下端點:
https://graph.windows.net/{myTenantId}/applications?api-version=1.6
以下是在響應正文:
{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."}}}
由於機構說「沒有足夠的權限來完成操作」,它似乎是一個簡單的權限問題,但我已授予Microsoft.Azure.ActiveDirectory API的以下權限(以全局管理員身份登錄時)是正在運行的代碼的應用程序:
- 訪問目錄作爲登錄用戶
- 讀寫的目錄數據
難道這些權限還不夠嗎?我錯過了什麼?正如我所說的,使用流暢的API創建其他資源工作得很好。
非常感謝您在構建您所示的IAzure客戶端時能夠正常工作。以前,我只在應用程序中使用clientId/clientSecret(在Portal中使用手動授予的權限),這也許是問題所在。 – tremolo