2017-03-04 195 views
-1

我堅持使用REST API用於獲取訂閱計費信息從Resource Usage API如何獲取從蔚藍

我想獲得與如何獲得令牌非交互式客戶端幫助驗證訪問令牌。我選擇使用REST API,因爲Azure客戶端似乎不支持資源使用API​​。

由於Authorization code grant (interactive clients)描述,我用我的訂閱ID調用了請求,但令牌沒有正確返回。

[[email protected] src]# curl -XPOST https://login.microsoftonline.com/xxxxx/oauth2/token -d "" 
{"error":"invalid_request","error_description":"AADSTS90014: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 32981285-a021-45c3-8d2f-62db49d2c2f1\r\nCorrelation ID: d88849dd-20f9-462e-9ce9-66b6fde0170e\r\nTimestamp: 2017-03-04 04:06:44Z","error_codes":[90014],"timestamp":"2017-03-04 04:06:44Z","trace_id":"32981285-a021-45c3-8d2f-62db49d2c2f1","correlation_id":"d88849dd-20f9-462e-9ce9-66b6fde0170e"}[[email protected] src]# 

如何獲取令牌?

+0

我不請求中沒有任何請求身體參數。你可以包括他們每個文件。 –

回答

1

,如果你如果想要做,例如,您的請求必須包含客戶端憑證的非交互式請求(URL編碼形式不提供某些憑據:)

令牌將不予退還格式):

  • grant_type = client_credentials
  • 的client_id =您的應用程序內的客戶端-ID
  • client_secret =您的應用程序內的客戶端祕密
  • 資源=資源-uri-for-api-you-want-the-token-for

對於Azure AD Graph API,資源URI可能是例如https://graph.windows.net/

如果您想使用用戶名和密碼,您還可以使用密碼授予令牌。在這種情況下,你必須發送:

  • CLIENT_ID,client_secret和資源如上
  • grant_type =密碼
  • 用戶名=您的戶名
  • 密碼=您的密碼
+0

謝謝,像一個魅力工作 – rinormaloku