使用Power查询在Power BI中生成JWT
我试图通过打电话给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:
In simpler words, I am trying to generate a JWT within Power Query function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论