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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is 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
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

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.