中的服务检索不记名令牌

中的服务检索不记名令牌

本文介绍了如何从 Power BI 中的服务检索不记名令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用 Web API - 例如,https://myresources/getresources.此调用需要 API 密钥、resourcesApiKey 和不记名令牌.必须从另一个服务 https://mytokenservice/jwt 获取令牌.它需要一个 API 密钥 tokenServiceApiKey.

I am attempting to call a web API-- say, https://myresources/getresources. This call requires an API Key, resourcesApiKey and a bearer token. The token must be acquired from another service, https://mytokenservice/jwt. It requires an API key, tokenServiceApiKey.

我可以通过手动访问令牌服务并输入值来获取我的资源数据,但我希望 Power BI 为我处理所有这些.我在这里阅读了一些关于此的内容,但是这似乎适用于静态令牌.我们的情况发生了变化,因此我需要实际调用此服务.

I'm able to get my resource data by manually accessing the token service and entering values, but I'd like to have Power BI take care of all this for me. I read something about this here, but this seems to apply to a static token. Ours changes, so I need to actually call out to this service.

所以,我想要做的是:

  1. 在我的报告中保存令牌服务 URL 和 API 密钥.运行报告时,Power BI 应使用 url 和密钥来检索不记名令牌.
  2. 在我的报告中保存资源 API url 和 api 密钥.将在步骤 1 中检索到的不记名令牌以及资源 API 密钥应用于对资源 API url 进行的调用,以检索我真正需要的数据.

我认为描述的方法 此处 适用,但我无法使其正常工作.以下是我最近尝试使用 Power BI 高级编辑器进行的操作:

I think the approach described here applies, but I can't get it to work. Here's what I most recently tried using the Power BI advanced editor:

  • 我使用管理参数在 Power BI 中创建了一个参数,然后使用高级编辑器,我输入了以下内容:

  • I created a parameter in Power BI using Manage Parameters, then used Advanced Editor, I entered the following:

网页内容(https://mytokenservice/jwt",[ApiKeyName=tokenServiceApiKey"])

Web.Content("https://mytokenservice/jwt",[ApiKeyName="tokenServiceApiKey"])

我还为 tokenServiceApiKey 和 resourcesApiKey 创建了 Power BI 参数,其中包含每个参数的密钥.

I also created Power BI parameters for tokenServiceApiKey and resourcesApiKey that contain the key for each.

当我点击完成"时但是,在高级编辑器中,它会自动围绕我编写的内容生成一些代码,以便现在读取,

When I clicked "Done" in the Advanced Editor, though, it automatically generated some code around what I'd written, so that it now reads,

Html.Table(Web.Content("https://mytokenservice/jwt",[ApiKeyName="tokenServiceApiKey"]), {})

编辑器中出现的是一个不包含数据的表格图标.我应该拿回一个字符串.我不知道从哪里开始,而且在网上找不到答案.

What appears in the editor is a table icon containing no data. I should be getting a string back. I don't know where to go from here and am having trouble finding answers online.

有没有办法完成我所追求的?

Is there anyway to accomplish what I'm after?

我可能没有很好地解释它,所以如果您需要更多信息或澄清,请提出问题.

I probably haven't explained it very well, so please ask questions if you need more information or clarification.

推荐答案

Number-1:您可以根据自己的目的构建自己的数据连接器.一些指南可以在这里找到 - 点击这里

Number-1: You can build your own data connector for your purpose. Some guidelines will find here- Click Here

NUMber-2:您还可以使用电源查询来连接您的信号源.最近我使用 oAuth2 API 为客户收集了数据.您可以使用 Power/M Query 连接到任何 API.以下是我的案例的示例代码,在第一部分中,我收集了 access_token,在第二步中,我使用该访问令牌收集了数据.希望这能让您对使用 Power Query 连接到任何 API 有所了解.

NUmber-2: You can also use power query to connect your source. Recently I have collected data for clients using oAuth2 API. You can connect to any API using Power/M Query. Following is the sample code for my case, where in the first part I have collected the access_token and in second step, I have collected data using that access token. hope this will give you some idea on connecting to any API using Power Query.

let
    url = "your_authentication_url_here",

    body  = "{ ""client_id"": ""****"",  ""client_secret"": ""****"", ""grant_type"": ""****"", ""audience"":""****""}",
    tokenResponse = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body) ] )),
    AccessToken = tokenResponse[access_token],
    AccessTokenHeader = "Bearer " & AccessToken,


    data_url = "your_main_url_here",
    data_body = "{
                    ""authorization"": """& AccessTokenHeader & """,
                    ""content-type"": ""application/json""
                }",

    GetGroups = Json.Document(
        Web.Contents(
            data_url,
            [
                Headers = Json.Document(data_body)
            ]
        )
    ),

    categories = GetGroups[categories], --Category here will be changed as per your retrned data

    #"Converted to Table" = Table.FromList(categories, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn
    (
        #"Converted to Table", "Column1",
        {"ext_id", "shared", "report", "query", "_id", "description"}, --This is column returned from your data set
        {"ext_id", "shared", "report", "query", "_id", "description"}  -- Rename columns accordingly
    )
in
    #"Expanded Column1"

这篇关于如何从 Power BI 中的服务检索不记名令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 06:59