Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass several parameters in StartLogin function

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.

like image 666
sudeepdino008 Avatar asked Aug 25 '17 12:08

sudeepdino008


1 Answers

You don't need to pass the variables into StartLogin function to construct the AuthorizeUrl. Instead, you can just declare them as global variables so the StartLogin can access them to construct the AuthorizeUrl.

e.g.

hostname = ...;
environment = ...;
authorize_uri = hostname & "/" & getOAuthUrlFromEnvName(environment) & "/oauth/authorize?"

StartLogin = (resourceUrl, state, display) =>
    let
        authorizeUrl = authorize_uri & "?" & Uri.BuildQueryString([
        ...
like image 173
Foxan Ng Avatar answered Oct 20 '22 05:10

Foxan Ng