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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.