使用Power查询在Power BI中生成JWT

发布于 2025-01-29 01:09:15 字数 1085 浏览 3 评论 0原文

我试图通过打电话给REST API来检索Oauth代币。我已经成功地使用了下面的电源查询函数来成功这样做:

let

GetJson = Web.Contents("https://my-oauth-provider/adfs/oauth2/token",
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("[email protected]&client_assertion=eyJhbGciOiJSUzI1NiIsImtp...&grant_type=client_credentials&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&resource=urn://gaurav")
]
),
FormatAsJson = Json.Document(GetJson),
#"Converted to Table" = Record.ToTable(FormatAsJson),
access_token = #"Converted to Table"{0}[Value]
in
access_token

但是,我们传递给Oauth Rest API的参数之一是客户端的断言,即本身就是一个需要在主机计算机上生成的JWT令牌。

目前,我使用C#实用程序生成了此客户主张令牌,但是我们不希望将此实用程序运送到客户。相反,如果用户在他的计算机上安装了必要的证书,我想编写一个电源查询功能,该功能可以读取该证书并为我生成一个带有所需索赔的JWT令牌。

我想做的是在邮递员中看起来像:

I am trying to retrieve an OAuth token by making a call to a Rest API. I have been successfully able to do so using a power query function like below:

let

GetJson = Web.Contents("https://my-oauth-provider/adfs/oauth2/token",
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("[email protected]&client_assertion=eyJhbGciOiJSUzI1NiIsImtp...&grant_type=client_credentials&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&resource=urn://gaurav")
]
),
FormatAsJson = Json.Document(GetJson),
#"Converted to Table" = Record.ToTable(FormatAsJson),
access_token = #"Converted to Table"{0}[Value]
in
access_token

However, one of the parameter that we pass to OAuth Rest API is client assertion that in itself is a JWT token that needs to be generated on the host machine.

At the moment, I generate this client assertion token using a C# utility however we do not wish to ship this utility to our clients. Rather, if a user has installed the necessary certificate on his machine, I want to write a Power query function that can read that certificate and generate me a JWT token with the required claims in it.

What I am trying to do looks something in Postman like:

Postman call to get oauth token

In simpler words, I am trying to generate a JWT within Power Query function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文