powerbi - Power BI API Authentication Issue After Publishing (JWT Token) - Stack Overflow

I'm using Power BI with a REST API as a data source. The API requires authentication via a JWT tok

I'm using Power BI with a REST API as a data source. The API requires authentication via a JWT token. In Power BI Desktop, I created a Power Query function that retrieves a new token using credentials and then applies it to API requests. This works perfectly on my local machine.

However, after publishing to Power BI Service, I can't connect to the API. The dataset shows as offline due to credential issues, and I'm unable to save authentication settings (Anonymous/Organizational). It seems Power BI Service does not execute the function that retrieves the token, causing authentication to fail.

Is there any way to make this work? Does Power BI Service support API authentication with dynamic tokens, or do I need an alternative approach?

I already tried to save the credentials as Anonymous and Organizational, but it didn't save. I also tried to find a way to define a header in Power BI Service with the username and password used in my API to get the JWT token, but I don't think there's a way to do this in app.powerbi.

I expect my report to be able to access my API in the app.powerbi, use the function I created to generate a JWT Token, access the route defined in my query and refresh the table I published

Function to obtain a new JWT Token

let
    GetAuthToken = () as text => 
    let
        authUrl = "https://localhost/api/auth/login",
        authBody = "{""Nome"":""admin"",""senha"":""Teste123""}",
        authHeaders = [
            #"Content-Type" = "application/json",
            #"Accept" = "application/json"
        ],
        authResponse = Json.Document(Web.Contents(authUrl, [
            Headers = authHeaders, 
            Content = Text.ToBinary(authBody), 
            ManualStatusHandling = {400, 401, 403}
        ])),
        token = authResponse[token]  // Ajustado para o nome correto
    in
        token
in
    GetAuthToken

Power Query of a example table

let
    Fonte = Json.Document(Web.Contents("http://localhost/api/operacoes/almoxarifados", [Headers=[Authorization="Bearer " & #"GET Access Token"()]])),
    #"Convertido para Tabela" = Table.FromList(Fonte, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Column1 Expandido" = Table.ExpandRecordColumn(#"Convertido para Tabela", "Column1", {"codigo", "filial", "nome", "ult_Qtd", "ult_Custo", "almoxarifado_de_Venda"}, {"codigo", "filial", "nome", "ult_Qtd", "ult_Custo", "almoxarifado_de_Venda"})
in
    #"Column1 Expandido"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744228925a4564148.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信