Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Power BI Service changes the State header for a custom connector

Hello there,

I've developed my own custom connector for Power BI and it works well in Power BI Desktop.

The issue I faced is Power BI service changes the header called "State" when it sends a query for OAuth2 start login function.

PBI service puts there "app.powerbi.com" as state always.

For the most cases it's not a problem I think but in my cases this strange behavior breaks my plans because the server I'm sending REST API calls to requires the length of state header has to be 24 symbols at least. For this reason I can't run my connector on PBI service.

Can somebody explain why it happens? Is it the bug?

Alex

3 REPLIES 3
GilbertQ
Super User
Super User

Hi there

Could you give a working example of what it looks like in PBI Desktop and what you want to do in the PBI Service?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

Hi @GilbertQ ,

Thanks for your reply.

The connector is written for Netsuite system by Oracle.

Bellow are the steps of issue I've faced.

1. The following code implements OAuth 2.0 in my connector:

 StartLogin = (resourceUrl, state, display) =>
     let
        clientId = devClientId,
        
        AuthorizeUrl = authURL & "?" & Uri.BuildQueryString([
            response_type = "code",
            state = "ykv2XLx1BpT5Q0F3MRPHb94j",
            client_id = clientId,  
            scope = "restlets",
            redirect_uri = redirectURL
           
        ])
    in
        [
            LoginUri = AuthorizeUrl,
            CallbackUri = redirectURL,
            WindowHeight = windowHeight,
            WindowWidth = windowWidth,
            Context = []
        ];

FinishLogin = (context, callbackUri, state) =>
    let
        parts = Uri.Parts(callbackUri)[Query],
        result = if (Record.HasFields(parts, {"error", "error_description"})) then 
                    error Error.Record(parts[error], parts[error_description], parts)
                 else
                    TokenMethod("authorization_code", "code", parts[code])
    in
        result;

TokenMethod = (grantType, tokenField, code) =>
    let
        clientId     = devClientId,
        clientSecret = devClientSecret,
        
        queryString = [
            client_id = clientId,
            client_secret = clientSecret,
            grant_type = grantType,
            redirect_uri = redirectURL
        ],
        queryWithCode = Record.AddField(queryString, tokenField, code),

        tokenResponse = Web.Contents(tokenURL, [
            Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
            Headers = [
                #"Content-type" = "application/x-www-form-urlencoded",
                #"Accept" = "application/json"
            ],
            ManualStatusHandling = {400} 
        ]),
        body = Json.Document(tokenResponse),
        result = if (Record.HasFields(body, {"error", "error_description"})) then 
                    error Error.Record(body[error], body[error_description], body)
                 else
                    body
    in
        result;

As you can see the code above is absolutely standard OAuth 2.0 implementation.

 

2. When I try signing in from Power BI Desktop I get the following in Fiddler:

2020-10-13_09-45-31.png

 

As it's shown on the picture above Power BI Desktop sends exactly the same state header as it is in connector code.

 

3. Ok, I created a report and published it on Power BI Service.

Now I'm trying to add a data source to my gateway:

AlexanderIvanov_0-1602568528007.png

When I click the "Sign in" button the login window appears but pay attention at this:

AlexanderIvanov_1-1602568697493.png

 

Why is there changed state header? My connector does not send "app.powerbi.com"!

As result I can't authorize my connector from Power BI service and all my plans are ruined.  😞

Hi there

I would suggest moving this to the Developer forum so someone with more experience with Custom connectors can assist you with how to solve your challenge.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors