Forum Discussion

ishaqw's avatar
ishaqw
New Member
4 years ago

Custom Connector Power BI - Using OAuth2 not working

Hi 

This is my first attempt in building a custom connector and I have gone through a few web posts and Power BI videos to build a custom Power BI connector, but am not getting past the login page. I am hard coded the credentials (Client ID, Client Secret) just to establish connection using OAuth but cannot get past the login prompt.

 

Could someone please assist with the below M code in pq file. Any help would be appreciated.

 

// This file contains your Data Connector logic
section PropertyIQ;

OAuthBaseUrl = "https://---.com.au";
client_id = client_id;
client_secret = client_secret;
redirect_uri = "https://oauth.powerbi.com/views/oauthredirect.html";

[DataSource.Kind="PropertyIQ", Publish="PropertyIQ.Publish"]
shared PropertyIQ.Contents =
let
currentCreadentials =Extension.CurrentCredential(),
source = Web.Contents(OAuthBaseUrl & "/api/buildings")
in
source;


TokenMethod = (code) =>
let
Response = Web.Contents(OAuthBaseUrl & "/login/oauth/access_token", [
Content = Text.ToBinary(Uri.BuildQueryString([
client_id = client_id,
client_secret = client_secret,
code = code,
redirect_uri = redirect_uri])),
Headers=[#"Content-type" = "application/json",#"Accept" = "application/json"]]),
Parts = Json.Document(Response)
in
Parts;

// Data Source Kind description
PropertyIQ = [
StartLogin = (resourceUrl, state, display) =>
let
AuthorizeUrl = OAuthBaseUrl & "/oauth/access_token?" & Uri.BuildQueryString([
client_id = client_id,
scope = "arrears buildings lots suppliers",
state = state,
redirect_uri = redirect_uri])
in
[
LoginUri = AuthorizeUrl,
CallbackUri = redirect_uri,
WindowHeight = 768,
WindowWidth = 1024,
Context = null
],
FinishLogin = (context, callbackUri, state) =>
let
Parts = Uri.Parts(callbackUri)[Query]
in
TokenMethod(Parts[code]),

Authentication = [
OAuth = [
StartLogin = StartLogin,
FinishLogin = FinishLogin
]
],
Label = Extension.LoadString("DataSourceLabel")
];

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

PropertyIQ.Icons = [
Icon16 = { Extension.Contents("PropertyIQ16.png"), Extension.Contents("PropertyIQ20.png"), Extension.Contents("PropertyIQ24.png"), Extension.Contents("PropertyIQ32.png") },
Icon32 = { Extension.Contents("PropertyIQ32.png"), Extension.Contents("PropertyIQ40.png"), Extension.Contents("PropertyIQ48.png"), Extension.Contents("PropertyIQ64.png") }
];

 

2 Replies

  • Hi Stephen, 

    Thank you for providing the details I have been unwell and have not been able to work on it but will do coming week.

    In brief it is exactly what I needed, so I will follow the guidance provided and confirm back soon.

    Regards

    Waseem