Power BI-从Auth API获取JWT令牌

Power BI-从Auth API获取JWT令牌,jwt,powerbi,asp.net-core-webapi,Jwt,Powerbi,Asp.net Core Webapi,我开发了一个API,它需要包含用户声明的JWT访问令牌,并且必须作为授权头提交才能获取任何数据。当通过Postman或.NETHTTP客户机发出请求时,它工作得非常好,这是非常标准的实现 我们的企业现在希望使用Power BI通过我们的API连接到数据。我们在这方面没有太多经验,但我了解基本原理。观看了一些PluralSight视频等,以熟悉我自己。我真正遇到的问题是如何获取用于查询的令牌 我在谷歌上搜索了一下,找到了我想要的最后一个答案 我有一个疑问: let GetJson = Web.C

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

我们的企业现在希望使用Power BI通过我们的API连接到数据。我们在这方面没有太多经验,但我了解基本原理。观看了一些PluralSight视频等,以熟悉我自己。我真正遇到的问题是如何获取用于查询的令牌

我在谷歌上搜索了一下,找到了我想要的最后一个答案

我有一个疑问:

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查询设置,这实际上没有帮助,因为这是一篇没有身份验证的HTTP文章(因此设置为匿名)。有什么想法可以解决这个问题吗?

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


问题现在解决了。现在我只需要了解如何在另一个查询中使用access_令牌…

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

问题现在解决了。现在我只需要知道如何在另一个查询中使用access_令牌

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