gpt4 book ai didi

oauth-2.0 - 在 StartLogin 函数中传递几个参数

转载 作者:行者123 更新时间:2023-12-04 01:48:10 26 4
gpt4 key购买 nike

我正在构建一个自定义连接器以通过 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中。我如何通过 hostnameenvironment都到 StartLogin功能?我基本上需要这两个变量来构造 resourceUrl .任何引用资料也会有所帮助。

最佳答案

您不需要将变量传递到 StartLogin构造AuthorizeUrl的函数.相反,您可以将它们声明为全局变量,因此 StartLogin可以访问它们来构造 AuthorizeUrl .

例如

hostname = ...;
environment = ...;
authorize_uri = hostname & "/" & getOAuthUrlFromEnvName(environment) & "/oauth/authorize?"
StartLogin = (resourceUrl, state, display) =>
let
authorizeUrl = authorize_uri & "?" & Uri.BuildQueryString([
...

关于oauth-2.0 - 在 StartLogin 函数中传递几个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45881474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com