Azure HTTP POST 请求来自 Power BI 的访问令牌

Azure HTTP POST requests for an access token from Power BI

是否可以使用 HTTP POST 请求从 Power BI 电源查询获取 azure AD 应用程序访问令牌?

HTTP POST 请求:

//request url
https://login.microsoftonline.com/<tenant id>/oauth2/token

//header
Content-Type: application/x-www-form-urlencoded

//request body
grant_type=client_credentials
client_id=625bc9f6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
client_secret=bCBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
resource=api://xxxxxxxxxxxxxxxxxxxxxxxxxxx

参考:https://docs.microsoft.com/en-us/azure/active-directory/azuread-dev/v1-oauth2-client-creds-grant-flow#example

好的,它看起来很简单,并且可以很好地处理 Postmanpython 请求,并显示带有 json 数据的成功响应。 现在我的问题是我想用 Power BI power query 通过这个请求这是我的 power query

let
  apiUrl = "https://login.microsoftonline.com/<tenant id>/oauth2/token",
    body = "{
    ""grant_type"": ""client_credentials"",
    ""client_id"": ""625bc9f6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",
    ""client_secret"": ""bCBxxxxxxxxxxxxxxxxxxxxxxxxxxx"",
    ""resource"": ""api://xxxxxxxxxxxxxxxxxxxxxxxxxxx""
    }",

  Source = Web.Contents(apiUrl, [Headers=[#"Content-Type"="application/x-www-form-urlencoded"],
           Content=Text.ToBinary(body)]),
  FormatAsJson = Json.Document(Source)
in
    FormatAsJson

但是它说请求错误

DataSource.Error: Web.Contents failed to get contents from 
'https://login.microsoftonline.com/61ed5503-xxxxxxxxxxxxxxxxx/oauth2/token' (400): Bad Request

我错过了什么或者为什么它说请求错误? 是不是REST API的原因吗? 还是有其他方法可以实现?

我解决了,实际上我不得不添加一些额外的条款,也是我自己犯的一个愚蠢的错误, 正确的查询

let
  apiUrl = "https://login.windows.net/61xxxxxxxxxxxx/oauth2/token",
    body = [
          client_id="3728xxxxxxxxxxxxxx5",
          grant_type="client_credentials",
          client_secret="bxxxxxxxxxxxxh",
          resource="api://xxxxxxxxxxxxxxxx5"
],

  Source = Json.Document(Web.Contents(apiUrl, [Headers = [Accept = "application/json"],
 Content = Text.ToBinary(Uri.BuildQueryString(body))]))
in
Source