# What application type should I choose for a Power BI custom data connector

**URL:** <https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [April 15, 2021, 10:17am UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145 "2021-04-15T10:17:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [April 15, 2021, 10:17am UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/1 "2021-04-15T10:17:40Z")

</div>

Hi everyone.

I’m developing a [custom Power BI data connector,](https://docs.microsoft.com/en-us/power-query/startingtodevelopcustomconnectors) that will authorize with Auth0 using oAuth.

When end-users use this connector, they will have to login the first time. The custom data connector should then use refresh tokens, so it won’t need to ask for a new token again (power bi app’s will maybe refresh in the background, 2 times a day).

So in Auth0 I’m creating an application for this data-connector. What application type should I pick?

---

<div class="post-metadata">

**Author:** ![cibrax](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cibrax/32/27644_2.png) [@cibrax](https://community.auth0.com/u/cibrax)\
**Post date:** [April 15, 2021, 1:10pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/2 "2021-04-15T13:10:57Z")

</div>

Hi Alex,

I am sorry, I am not familiar on how a Power BI connector is implemented, does it have a front-end and backend or it’s just a front-end ?. If you have backend, you can use a web application. Otherwise, it would be a Single Page Application that uses PKCE. The later is a public client so it does not need a secret, but you can not store refresh tokens on it (See this other article for that scenario, [Refresh Token Rotation](https://auth0.com/docs/tokens/refresh-tokens/refresh-token-rotation))  
I hope that helps

Pablo.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 15, 2021, 2:00pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/3 "2021-04-15T14:00:54Z")

</div>

Thanks for contributing to this one @cibrax !

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [April 16, 2021, 7:51am UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/4 "2021-04-16T07:51:16Z")

</div>

Hi @cibrax - thanks for helping out.

That are some really good questions. I don’t know if the Power BI connector can be treated as a backend, I’m trying to answer that know. Thanks for the help 😌

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [April 19, 2021, 8:47pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/5 "2021-04-19T20:47:47Z")

</div>

Hi @cibrax .

I found [this article](https://docs.microsoft.com/en-us/power-query/handlingauthentication#implementing-an-oauth-flow) from microsoft regarding oAuth and custom data connectors;

> Power Query extensions are evaluated in applications running on client machines. Data Connectors _should not_ use confidential secrets in their OAuth flows, as users may inspect the extension or network traffic to learn the secret. See the [Proof Key for Code Exchange by OAuth Public Clients RFC](https://tools.ietf.org/html/rfc7636) (also known as PKCE) for further details on providing flows that don’t rely on shared secrets. A [sample](https://github.com/microsoft/DataConnectors/blob/master/samples/OAuthPKCE/PKCESample.pq) implementation of this flow can be found on our GitHub site.

So does that mean application type of either native or SPA, if I understand correctly?

---

<div class="post-metadata">

**Author:** ![cibrax](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cibrax/32/27644_2.png) [@cibrax](https://community.auth0.com/u/cibrax)\
**Post date:** [April 19, 2021, 9:10pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/6 "2021-04-19T21:10:38Z")

</div>

That actually helps a lot. Your connector is a public client, so you should configure it as SPA. That will use PCKE under the hood.

Best regards  
Pablo

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [April 19, 2021, 9:18pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/7 "2021-04-19T21:18:08Z")

</div>

Now that I have your attention 😅

Would this flow allow for refresh tokens to be used? My ideal scenario is that the end-user will only authenticate _once_, when the custom data connector is “installed” for the first time. Do you think such a thing would be possible?

---

<div class="post-metadata">

**Author:** ![cibrax](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cibrax/32/27644_2.png) [@cibrax](https://community.auth0.com/u/cibrax)\
**Post date:** [April 19, 2021, 10:41pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/8 "2021-04-19T22:41:07Z")

</div>

Yes, absolutelly! That is possible with refresh token rotation. See this,

> **[Refresh Token Rotation](https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation)**
>
> Describes how refresh token rotation provides greater security by issuing a new refresh token with each request made to Auth0 for a new access token by a client using refresh tokens.

Thanks  
Pablo

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 20, 2021, 12:03pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/9 "2021-04-20T12:03:12Z")

</div>

Teamwork makes the dreamwork!

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [April 23, 2021, 5:30am UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/10 "2021-04-23T05:30:12Z")

</div>

I now have a working solution, where the custom data source connector uses the PCKE flow. It works great - and I don’t have to provide the client secret. Thanks for the awesome help 👍 Now I’m just trying to understand the potential gains/consequences if I enable rotating refresh tokens 🤔

---

<div class="post-metadata">

**Author:** ![jjkaandorp](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jjkaandorp/32/28987_2.png) [@jjkaandorp](https://community.auth0.com/u/jjkaandorp)\
**Post date:** [April 23, 2021, 2:32pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/11 "2021-04-23T14:32:31Z")

</div>

Hi Alex,  
Please share your solution.  
Regards,  
Sjaak.

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [April 26, 2021, 11:01am UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/12 "2021-04-26T11:01:01Z")

</div>

Hi @jjkaandorp.

Roger. So the solution from a Power BI custom data connector oAuth implementation with PCKE flow looks like this. If you have any questions or comments, please let me know. Some comments:

- Make sure your auth0 login page supports IE 11
- You need offline enabled for the below to work

**Helper variables**

```auto
client_id = "<AUTH0 CLIENT ID>"; 
redirect_uri = "https://oauth.powerbi.com/views/oauthredirect.html";
authorize_uri = "https://<YOUR_AUTH_DOMAIN>.com/authorize";
token_uri = "https://<YOUR_AUTH_DOMAIN>.com/oauth/token";
windowWidth = 1200;
windowHeight = 1000;
codeVerifier = Text.NewGuid() & Text.NewGuid();

```

**Start login function**

```auto
StartLogin = (resourceUrl, state, display) =>
    let
        params = Json.Document(resourceUrl),
        codeChallenge = Base64UrlEncodeWithoutPadding(Crypto.CreateHash(CryptoAlgorithm.SHA256, Text.ToBinary(codeVerifier, TextEncoding.Ascii))),
        AuthorizeUrl = authorize_uri & "?" & Uri.BuildQueryString([
            client_id = client_id,
            scope = "openid offline_access",
            response_type = "code",
            state = state,
            redirect_uri = redirect_uri,
            code_challenge_method = "S256",
            code_challenge = codeChallenge
            
            
            ])
    in
        [
            LoginUri = AuthorizeUrl,
            CallbackUri = redirect_uri,
            WindowHeight = windowHeight,
            WindowWidth = windowWidth,
            Context = []
        ];

```

**Refresh your token**

```auto
Refresh = (resourceUrl, refresh_token) =>
    let
         result = TokenMethod("refresh_token", "refresh_token", refresh_token)
    in
        result;

```

**Finish login**

```auto
FinishLogin = (context, callbackUri, state) =>
    let
        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;

```

**Helper**

```auto
Base64UrlEncodeWithoutPadding = (hash as binary) as text =>
    let
        base64Encoded = Binary.ToText(hash, BinaryEncoding.Base64),
        base64UrlEncoded = Text.Replace(Text.Replace(base64Encoded, "+", "-"), "/", "_"),
        withoutPadding = Text.TrimEnd(base64UrlEncoded, "=")
    in 
        withoutPadding;

```

**TokenMethod**

```auto
TokenMethod = (grantType, tokenField, code) =>
    let
        queryString = [
            grant_type = grantType,
            redirect_uri = redirect_uri,
            client_id = client_id,
            code_verifier = codeVerifier
        ],
        // hans = Diagnostics.Trace(TraceLevel.Information, "TokenMethod: " & code, code),
        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",
                #"Accept" = "application/json"
            ],
            ManualStatusHandling = {400} 
        ]),
        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;

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 26, 2021, 12:44pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/13 "2021-04-26T12:44:19Z")

</div>

Thanks for sharing that with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 29, 2021, 12:57pm UTC](https://community.auth0.com/t/what-application-type-should-i-choose-for-a-power-bi-custom-data-connector/61145/14 "2021-04-29T12:57:27Z")

</div>


