我正在构建一个自定义连接器以通过 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
],
我现在需要另一个参数作为用户的输入。hostname它在ui中调用。我如何通过hostname并environment同时发挥StartLogin作用?我基本上需要这两个变量来构造resourceUrl. 任何参考资料也会有所帮助。