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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
ishaqw
New Member

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 2
ishaqw
New Member

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

Anonymous
Not applicable

Hi @ishaqw ,

 

See if this blog is helpful: Building a custom connector for Power BI that supports OAuth2 to visualize my wellness data - Jussi ...

 

Also, in this official document, it has Refresh and Logout section after FinishLogin section while your codes don't. Not sure if this is the cause. 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors