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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I am trying to implement OAuth in custom connector. I want to understand how to call correspond environments:
for example authorize_url and token_url, can be test or prod.
StartLogin = (resourceUrl, state, display) =>
let
AuthorizeUrl = authorize_url & Uri.BuildQueryString([
client_id = client_id,
response_type = "code",
code_challenge_method = "S256",
code_challenge = hash,
state = "test",
scope="openid",
redirect_uri = redirect_url])
in
[
LoginUri = AuthorizeUrl,
CallbackUri = redirect_url,
WindowHeight = windowHeight,
WindowWidth = windowWidth,
Context = null
];
FinishLogin = (context, callbackUri, state) =>
let
Parts = Uri.Parts(callbackUri)[Query]
in
TokenMethod("authorization_code", "code", Parts[code]);
TokenMethod = (grantType, tokenField, code) =>
let
Response = Web.Contents(token_url, [
Content = Text.ToBinary(Uri.BuildQueryString([
grant_type = "authorization_code",
code_verifier = verifier,
client_id=client_id,
client_secret=client_secret,
code = code,
redirect_uri = redirect_url])),
Headers=[#"Content-type" = "application/x-www-form-urlencoded", #"Accept" = "application/json"]]),
Parts = Json.Document(Response)
in
Parts;
I am getting from UI, before authorization environment value (see below)...how to pass it in authorization part?
[DataSource.Kind="TestProject", Publish="TestProject.Publish"]
shared TestProject.Contents = Value.ReplaceType(TestProjectImpl, TestProjectType);
TestProjectType = type function (
duration as (type number meta [
DataSource.Path = false,
Type = "Singleton",
MakeResourcePath = () => "TestProjectConnector",
ParseResourcePath = (resource) => { },
Documentation.FieldCaption = "Lookback duration",
Documentation.AllowedValues = { 1..30 },
Documentation.SampleValues = {"25"},
Documentation.FieldDescription = "Defines how many days starting from today the connector will look back in time. It can be maximum 30 days"
]),
environment as (type text meta [
Documentation.FieldCaption = "Environment",
Documentation.AllowedValues = { "Test", "Prod" },
Documentation.FieldDescription = "Defines which environment data, do you want access"
]))
as table meta [
// appears in the initial datasource parameter configuration dialog
Documentation.Name = "TestProject"
];
TestProjectImpl = (DurationValue as number, Environment as text) =>
let
Days = DurationValue,
Duration = Date.AddDays(CurrentDate,-Days),
BaseUrl = ApiUrl{[EnvironmentType=Environment]}[BaseUrl],
// Token = Token(BaseUrl),
NavigationTables =TestProjectNavTableQueryFolding(BaseUrl, Duration)
in
NavigationTables;
@Anonymous
I am not familiar with building custom connector. You may find some relevant blogs and posts:
oauth 2.0 - Pass several parameters in StartLogin function - Stack Overflow
Pass several parameters in StartLogin function - Intellipaat
Best Regards
Paul Zheng
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.