我正在构建一个自定义连接器,通过OAuth2连接到我们的API。这样我们就可以将我们的api用作数据源来驱动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 })
我使用了MakeResourcePath和ParseResourcePath函数来传递Environment
参数(该参数在Power BI网站/桌面应用中由用户输入)。这个参数被传递给StartLogin
函数来进行OAuth授权调用。
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
],
现在我需要用户输入另一个参数作为输入。在UI中它被称为hostname
。我该如何同时将hostname
和environment
传递给StartLogin
函数?我基本上需要这两个变量来构造resourceUrl
。任何参考资料也会很有帮助。