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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Pass parameters to StartLogin and Token methods in OAuth

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;

@artemus 

1 REPLY 1
Anonymous
Not applicable

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.