Power BI-从Auth API获取JWT令牌

鞋匠

我开发了一个API,该API需要包含用户声明的JWT访问令牌,并且必须作为授权标头提交才能获取任何数据。通过Postman或.NET HTTP Client发出请求时,它非常好用,这是非常标准的实现。

我们的企业现在希望使用Power BI通过我们的API连接到数据。我们没有太多经验,但我了解基本知识。w了一些PluralSight视频等,以熟悉自己。我真正遇到的问题实际上是获取要在查询中使用的令牌。

我四处搜寻,发现https://community.powerbi.com/t5/Desktop/Pull-data-from-RESTful-API-with-token-authentication/td-p/80531的最后一个答案似乎是我在寻找什么。

我有这个查询:

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尝试连接并显示错误“我们无法使用提供的凭据进行身份验证。请重试。” 如果单击“编辑凭据”按钮,则会转到该请求的Web查询设置,因为它是不带Auth的HTTP帖子(因此设置为“匿名”),因此并没有帮助。有什么想法要解决吗?

鞋匠

将查询更改为此(现在使用用户名和密码参数):

let

GetJson = Web.Contents("https://mydomain.co.uk/api/token",
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("grant_type=password&username=" &Username&"&password="&Password&"&clienttype=User")
]
),
FormatAsJson = Json.Document(GetJson),
#"Converted to Table" = Record.ToTable(FormatAsJson),
access_token = #"Converted to Table"{0}[Value]
in
access_token

现在问题解决了。现在我只需要弄清楚如何在另一个查询中使用access_token ...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章