来自Power BI的Azure HTTP POST访问令牌请求 [英] Azure HTTP POST requests for an access token from Power BI
本文介绍了来自Power BI的Azure HTTP POST访问令牌请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过HTTP POST请求从Power BI Power Query获取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
好的,它看起来非常简单,可以很好地处理Postman
或python
请求,并使用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
这篇关于来自Power BI的Azure HTTP POST访问令牌请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文