<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Custom Connector - Test connection fails when setting up gateway in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2113403#M32210</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;OAuth for custom connectors via gateways is currently supported only for gateway admins but not other data source users. Please check whether you are the gateway admin.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;For reference: &lt;A href="https://docs.microsoft.com/en-us/power-query/handlinggatewaysupport" target="_self"&gt;Handling Gateway Support&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please check your network, and add the url in white list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Oct 2021 09:39:51 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-10-04T09:39:51Z</dc:date>
    <item>
      <title>Custom Connector - Test connection fails when setting up gateway</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2108554#M32170</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I have built a custom connector that uses OAuth authentication. I set it as per the documentation so i have a StartLogin help function and a FinishLogin along with a TestConnection handler.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My connector is pulling data from an endpoint that requires a token exchange.&lt;/P&gt;&lt;P&gt;I have it all working just fine on the client when I use the connector. It does what I want it to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, once I publish the report and attempt to set up the gateway connection on the power bo portal, I get an issue when it tries to test the connection when we click the Edit Credentials button. For some reason, it seems to go to another URL from what I can see other than the authorization URL in the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can run it successfully in visual studio when debugging and from my power bi client.&amp;nbsp; I just can't get past the gateway set up screen when it&amp;nbsp; tries to test the connection....&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// This file contains your Data Connector logic
section PowerBiConnectorTest;

// OuraCloud OAuth2 values
client_id = "&amp;lt;my client id&amp;gt;";
client_secret = "&amp;lt;my client secret&amp;gt;";
redirect_uri = "https://localhost:8080";
token_uri = "https://login.microsoftonline.com/common/oauth2/token";
authorize_uri = "https://login.microsoftonline.com/common/oauth2/authorize";
logout_uri = "https://login.microsoftonline.com/logout.srf";

// Login modal window dimensions
windowWidth = 720;
windowHeight = 1024;


[DataSource.Kind="PowerBiConnectorTest", Publish="PowerBiConnectorTest.Publish"]
shared PowerBiConnectorTest.Contents = (url as text) =&amp;gt;
    let

       apiKey = Extension.CurrentCredential()[access_token],
        headers = [
        #"x-api-key" = "&amp;lt;my api key&amp;gt;",
        #"Authorization" = "Bearer " &amp;amp; apiKey,
        #"Content-Type" = "application/json"
        ],
        source = Web.Contents(url, [ Headers = headers, ManualCredentials = true ])

    in
        source; 

// Data Source Kind description
PowerBiConnectorTest = [
    TestConnection = (dataSourcePath) =&amp;gt; { "PowerBiConnectorTest.Contents", dataSourcePath },
    Authentication = [
        OAuth = [
            StartLogin=StartLogin,
            FinishLogin=FinishLogin
        ]
    ],
    Label = Extension.LoadString("DataSourceLabel")
];

// Data Source UI publishing description
PowerBiConnectorTest.Publish = [
    Beta = true,
    Category = "Other",
    ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
    LearnMoreUrl = "https://powerbi.microsoft.com/",
    SourceImage = PowerBiConnectorTest.Icons,
    SourceTypeImage = PowerBiConnectorTest.Icons
];

// Helper functions for OAuth2: StartLogin, FinishLogin, Refresh, Logout
StartLogin = (resourceUrl, state, display) =&amp;gt;
    let
        authorizeUrl = authorize_uri &amp;amp; "?" &amp;amp; Uri.BuildQueryString([
            response_type = "code",
            client_id = client_id,  
            response_mode = "query",
            redirect_uri = redirect_uri
        ])
    in
        [
            LoginUri = authorizeUrl,
            CallbackUri = redirect_uri,
            WindowHeight = 720,
            WindowWidth = 1024,
            Context = null
        ];

FinishLogin = (context, callbackUri, state) =&amp;gt;
    let
        // parse the full callbackUri, and extract the Query string
        parts = Uri.Parts(callbackUri)[Query],
        // if the query string contains an "error" field, raise an error
        // otherwise call TokenMethod to exchange our code for an access_token
        result = if (Record.HasFields(parts, {"error", "error_description"})) then 
                    error Error.Record(parts[error], parts[error_description], parts)
                 else
                    TokenMethod("authorization_code", "code", parts[code])
    in
        result;

//Refresh = (resourceUrl, refresh_token) =&amp;gt; TokenMethod("refresh_token", "refresh_token", refresh_token);
//Refresh = (resourceUrl, refresh_token) =&amp;gt; TokenMethod("authorization_code", "code", refresh_token);


//Logout = (token) =&amp;gt; logout_uri;

// see "Exchange code for access token: POST /oauth/token" at https://cloud.ouraring.com/docs/authentication for details
TokenMethod = (grantType, tokenField, code) =&amp;gt;
    let
        queryString = [
            grant_type = "authorization_code",
            redirect_uri = redirect_uri,
            client_id = client_id,
            client_secret = client_secret
        ],
        queryWithCode = Record.AddField(queryString, tokenField, code),

        tokenResponse = Web.Contents(token_uri, [
            Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
            Headers = [
                #"Content-type" = "application/x-www-form-urlencoded"
            ]
        ]),
        body = Json.Document(tokenResponse),
        result = if (Record.HasFields(body, {"error", "error_description"})) then 
                    error Error.Record(body[error], body[error_description], body)
                 else
                    body
    in
        result;

Value.IfNull = (a, b) =&amp;gt; if a &amp;lt;&amp;gt; null then a else b;



PowerBiConnectorTest.Icons = [
    Icon16 = { Extension.Contents("PowerBiConnectorTest16.png"), Extension.Contents("PowerBiConnectorTest20.png"), Extension.Contents("PowerBiConnectorTest24.png"), Extension.Contents("PowerBiConnectorTest32.png") },
    Icon32 = { Extension.Contents("PowerBiConnectorTest32.png"), Extension.Contents("PowerBiConnectorTest40.png"), Extension.Contents("PowerBiConnectorTest48.png"), Extension.Contents("PowerBiConnectorTest64.png") }
];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 16:29:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2108554#M32170</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-30T16:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Connector - Test connection fails when setting up gateway</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2108664#M32172</link>
      <description>&lt;P&gt;Here is a screenshot of what it is doing:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-09-30_11-30-14.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/604154iCA26BA91A0838C9B/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-09-30_11-30-14.png" alt="2021-09-30_11-30-14.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 16:31:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2108664#M32172</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-30T16:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Connector - Test connection fails when setting up gateway</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2113403#M32210</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;OAuth for custom connectors via gateways is currently supported only for gateway admins but not other data source users. Please check whether you are the gateway admin.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;For reference: &lt;A href="https://docs.microsoft.com/en-us/power-query/handlinggatewaysupport" target="_self"&gt;Handling Gateway Support&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please check your network, and add the url in white list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 09:39:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2113403#M32210</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-04T09:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Connector - Test connection fails when setting up gateway</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2114128#M32219</link>
      <description>&lt;P&gt;Hello @Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We were actually trying to hit that test link with gateway admin access.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some questions:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1. Regarding the url to whitelist, which URL do I need to add to the whitelist? My endpoint I am pulling data from? or the one in the screenshot?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Is just whitelisting from my network/firewall? Or does Power BI have some sort of whitelist control?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 14:56:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Test-connection-fails-when-setting-up-gateway/m-p/2114128#M32219</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-04T14:56:05Z</dc:date>
    </item>
  </channel>
</rss>

