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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.


v-jingzhan-msft
Community Support
Community Support

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors