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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors