I am building a custom connector to connect to our API via OAuth2. This is so we can use our api as a data source to powerbi.
// Resource definition
Resource = [
Description = "MyAPI",
Type = "Custom",
MakeResourcePath = (env) => env,
ParseResourcePath = (env) => {env},
Authentication = [OAuth=[StartLogin = StartLogin, FinishLogin = FinishLogin, Refresh = Refresh]],
......
Icons = [
Icon16 = { Extension.Contents("MyAPI10.png"), Extension.Contents("MyAPI20.png") }
],
Label = "MyAPI"
]
in
Extension.Module("MyAPI", { Resource })
I used MakeResourcePath and ParseResourcePath to pass the Environment
parameter (which is taken as input from the user in power bi site/desktop). This is passed to StartLogin
to make the OAuth authorize call.
StartLogin = (env, state, display) =>
let
resourceUrl = getOAuthUrlFromEnvName(env) & "/oauth/authorize",
AuthorizeUrl = resourceUrl & "?" & Uri.BuildQueryString([
client_id = getClientIdFromEnv(env),
response_type = "code",
state = state, // added by VM
redirect_uri = redirect_uri])
in
[
LoginUri = AuthorizeUrl,
CallbackUri = redirect_uri,
WindowHeight = windowHeight,
WindowWidth = windowWidth,
Context = env
],
I need another parameter as input from the user now. It's called hostname
in ui. How do I pass hostname
and environment
both to StartLogin
function? I basically need these two variables to construct resourceUrl
. Any references would be helpful too.