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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MFalk118
Frequent Visitor

OAuth Authentication in Power Query M

I have a query like this:

let
headers = [#"Prefer" = "odata.maxpagesize=10000" ],
updatedHeaders = Record.Combine({headers,GetOAuthHeader()}),
Source = Web.Contents("https://devnst.visionpeople.dk:9548/VisionProductsDK_BC99/api/v2.0/companies", [ Headers = updatedHeaders])
in
Source


the GetOAuthHeader basically just gets a Bearer token.
This has been working, but now, when i refresh in Desktop, it insist on trying to connect to https://devnst.visionpeople.dk:9548/VisionProductsDK_BC99/api/v2.0/companies and it cannot so it asks for credentials. Obviuosly i cannot give it any credentials, since they are specified in the Bearer
I have tried manually to just specify Anonymous in the Data Source settings, but it seems Power Bi Desktop tries to connect to the url directly (Not using my Bearer header), No matter what i try when refreshing the data.

This works perfectly in the service, but it is pretty annoing that i cannot update the data in Desktop anymore.

 

Does anybody have a solution to this?

3 REPLIES 3
MFalk118
Frequent Visitor

There was missing API Permissions in my OAuth client registration, so everything works in Power Bi, sorry for wasting your time :-S

MFalk118
Frequent Visitor

The problem is (apparently) that Desktop tries to authenticate the URL with anonymous Authentication, without calling my function that add's the bearer. So it seems that Desktop insists that an URL must allow anonymous. It has been working previously, and i have also found older posts, where people staes it works if they go to Data Source and just change the Authentication to anonymous.

But now when i refresh Desktop seems to call the Url directly, and then opens the "Access Web Content" dialog and asks my to authenticate.
If i call with the same bearer (Which i have obtained with my GetOAuthHeader function) from Postman it works, as expected.
I am however a bit unsure, if it is Desktop that makes the authentication, and i am considering inserting af proxy between Desktop and my API, so i can see what actually happens.


Anonymous
Not applicable

Hi @MFalk118 

 

It looks weird if it works in the service but fails in Desktop. Do you see any error when you try to refresh the data in Desktop? If you create a blank report and connect to the same data source with the same query, will it get the data successfully?

 

If GetOAuthHeader() is a custom function to get a Bearer token, can you test it individually to check whether it can return a Bearer token successfully?

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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