Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sbolton1855
Frequent Visitor

OAuth 2.0 and Power Query SDK

I am trying to create an OAauth 2.0 connector using Power Query SDK. A few issues I am facing.

AppTesting.PagedTable is not defined and when I run the project I get an error "The export AppTesting.Contents was exported multiple times."

It looks like there is a 'new' sdk for 'Visual Studio Code'  That is what I attempted to use after I failed to get the connector working with VS 2019 and the SKD.  Ill post that below (I just need one working)

 

https://learn.microsoft.com/en-us/power-query/samples/github/readme

https://learn.microsoft.com/en-us/power-query/handling-authentication

I have a few other projects, one I followed this tutorial and can post the code but I also receive other errors https://jussiroine.com/2019/02/building-a-custom-connector-for-power-bi-that-supports-oauth2-to-visu...

Non of the tutorials I am able to get working

 

 

 

// This file contains your Data Connector logic
[Version = "1.0.0"]
section AppTesting;

[DataSource.Kind="AppTesting", Publish="AppTesting.UI"]
shared AppTesting.Contents = Value.ReplaceType(AppTesting.Contents, type function (url as Uri.Type) as any);

// Error cant find the name AppTesting.PagedTable
[DataSource.Kind="AppTesting"]
shared AppTesting.PagedTable.PagedTable = Value.ReplaceType(AppTesting.PagedTable, type function (url as Uri.Type) as nullable table);

// Data Source Kind description
AppTesting = [
 Authentication = [
        OAuth = [
            StartLogin = StartLogin,
            FinishLogin = FinishLogin
        ]
    ]
];

StartLogin = (resourceUrl, state, display) =>
        let
            AuthorizeUrl = "https://xxxurl.com/oauth/v1/authorize" & Uri.BuildQueryString([
                client_id = "xxxxxxx",
                client_secret = "xxxxxx",
                scope = "user, repo",
                state = state,
                redirect_uri = "https://oauth.powerbi.com/views/oauthredirect.html"])
        in
            [
                LoginUri = AuthorizeUrl,
                CallbackUri = "https://oauth.powerbi.com/views/oauthredirect.html",
                WindowHeight = 720,
                WindowWidth = 1024,
                Context = null
            ];

FinishLogin = (context, callbackUri, state) =>
    let
        Parts = Uri.Parts(callbackUri)[Query]
    in
        TokenMethod(Parts[code]);


TokenMethod = (code) =>
    let
        Response = Web.Contents("https://xxxurl.com/oauth/v1/token", [
            Content = Text.ToBinary(Uri.BuildQueryString([
                client_id = @client_id,
                client_secret = @client_secret,
                code = code,
                redirect_uri = @redirect_uri])),
            Headers=[#"Content-type" = "application/x-www-form-urlencoded",#"Accept" = "application/json"]]),
        Parts = Json.Document(Response)
    in
        Parts;

// Data Source UI publishing description
AppTesting.Publish = [
    Beta = true,
    Category = "Other",
    ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
    LearnMoreUrl = "https://powerbi.microsoft.com/",
    SourceImage = AppTesting.Icons,
    SourceTypeImage = AppTesting.Icons
];



AppTesting.Icons = [
    Icon16 = { Extension.Contents("AppTesting16.png"), Extension.Contents("AppTesting20.png"), Extension.Contents("AppTesting24.png"), Extension.Contents("AppTesting32.png") },
    Icon32 = { Extension.Contents("AppTesting32.png"), Extension.Contents("AppTesting40.png"), Extension.Contents("AppTesting48.png"), Extension.Contents("AppTesting64.png") }
];

 

 

 

0 REPLIES 0

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.