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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
vsingh23
Regular Visitor

Custom Connector Oauth2

Hi Team,

 

We've Smile CDR fhir server that supports oauth2. We're trying to connect to it using power bi, for this we're creating custom connector. We've added power bi as a client in Smile CDR. In the code we're passing every details however, we're getting 404 error. I've shared the code and screenshots below. 

 

Code:

 

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

[DataSource.Kind="SmileCDR", Publish="SmileCDR.Publish"]
shared SmileCDR.Contents = (optional message as text) =>
let
_message = if (message <> null) then message else "(no message)",
a = "Hello from SmileCDR: " & _message
in
a;

// Data Source Kind description
SmileCDR = [
Authentication = [
OAuth = [
StartLogin = StartLogin,
FinishLogin = FinishLogin
]
],
Label = Extension.LoadString("DataSourceLabel")
];


StartLogin = (resourceUrl, state, display) =>
let
AuthorizeUrl = "http://xx.xx.xx.xx/issuer/oauth/authorize" & Uri.BuildQueryString([
client_id = "client_id",
scope = "scope",
state = state,
redirect_uri = " https://oauth.powerbi.com/views/oauthredirect.html"])
in
[
LoginUri = "http://xx.xx.xx.xx/issuer/oauth/authorize",
CallbackUri = " https://oauth.powerbi.com/views/oauthredirect.html",
WindowHeight = 800,
WindowWidth = 800,
Context = null
];


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


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


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

SmileCDR.Icons = [
Icon16 = { Extension.Contents("SmileCDR16.png"), Extension.Contents("SmileCDR20.png"), Extension.Contents("SmileCDR24.png"), Extension.Contents("SmileCDR32.png") },
Icon32 = { Extension.Contents("SmileCDR32.png"), Extension.Contents("SmileCDR40.png"), Extension.Contents("SmileCDR48.png"), Extension.Contents("SmileCDR64.png") }
];

 

After running the code we're able to reach to signin page of Smile CDR. On sign in page we're passing the credentials and then we're getting 404 error as displayed in the screenshot. 

 

Could anyone provide any suggestions?

1st1st2nd2nd3rd3rd

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @vsingh23 

 

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,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors