Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.
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
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:
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:
When I click the "Sign in" button the login window appears but pay attention at this:
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. 😞