Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.
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") }
];
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
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.