【发布时间】:2018-12-04 01:11:40
【问题描述】:
我开发了一个 API,它需要包含用户声明的 JWT 访问令牌,并且必须作为 Authorization 标头提交才能获取任何数据。它在通过 Postman 或通过 .NET HTTP 客户端发出请求时运行良好,并且是非常标准的实现。
我们的企业现在希望使用 Power BI 通过我们的 API 连接到数据。我们没有太多经验,但我了解基本原理。观看了一些 PluralSight 视频等以熟悉自己。我真正遇到的问题实际上是获取用于查询的令牌。
我搜索了一下,发现https://community.powerbi.com/t5/Desktop/Pull-data-from-RESTful-API-with-token-authentication/td-p/80531 的最后一个答案似乎是我正在寻找的。p>
我有这个问题:
let
GetJson = Web.Contents("https://mydomain.co.uk/api/token",
[
Headers = [#"Accept"="application/json",
#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("grant_type=password&username=me&password=My_Pass11")
]
),
FormatAsJson = Json.Document(GetJson),
#"Converted to Table" = Record.ToTable(FormatAsJson),
#"Expanded Value" = Table.ExpandRecordColumn(#"Converted to Table", "Value", {"Data"}, {"Data"}),
#"Expanded Data" = Table.ExpandRecordColumn(#"Expanded Value", "Data", {"access_token", "expires_in", "culture", "resourceList", "roles", "applicationId", "userCurrency", "userDateFormat", "userProductWeight", "roleNames"}, {"access_token", "expires_in", "culture", "resourceList", "roles", "applicationId", "userCurrency", "userDateFormat", "userProductWeight", "roleNames"}),
access_token = #"Expanded Data"{0}[access_token]
in
access_token
可以理解为什么会这样,但是当我关闭查询编辑器时,Power BI 会尝试连接并显示错误“我们无法使用提供的凭据进行身份验证。请重试。” 如果我单击 Edit Credentials 按钮,我会转到请求的 Web 查询设置,这并没有真正的帮助,因为它是一个没有 Auth 的 HTTP Post(因此设置为 Anonymous)。关于如何解决这个问题的任何想法?
【问题讨论】:
标签: jwt powerbi asp.net-core-webapi