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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Use Master User for auto login to Power Bi Embedded (for customers) in Xamarin Forms app

Good day to all of you. I have a problem with probably not fully understanding how to embed PBI report in my Xamarin app. 
I got my token and I used Master User for this, but when I put my EmbedUrl in Source proprety of WebView, i get a message: "Please sing in to view this report". This is a problem because my customers don't have PowerBi account and I want them to be able to see this report. Problem might be in my headers I use to get token, so below is code I use

 

string url = "https://login.microsoftonline.com/" + tennant_id + "/oauth2/token"; //url to which I POST to

IEnumerable<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("authenticationType", "MasterUser"),
new KeyValuePair<string, string>("name", "<name>"),
new KeyValuePair<string, string>("workspaceId", "<workspaceId>"),
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("scope", "https://analysis.windows.net/powerbi/api/.default"),
new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"),
new KeyValuePair<string, string>("authorityUrl", "https://login.microsoftonline.com/organizations/"),
new KeyValuePair<string, string>("urlPowerBiServiceApiRoot", "https://api.powerbi.com/"),
new KeyValuePair<string, string>("client_id", "<clientID>"),
new KeyValuePair<string, string>("username", "<username>"),
new KeyValuePair<string, string>("password", "<password>"),
new KeyValuePair<string, string>("client_secret", "<clientSecret>")
};

 

 After I get access token, I use it in GET request to 

 

https://api.powerbi.com/v1.0/myorg/reports/<report_it>

 

 and I pass AuthenticationHeader as 

 

client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);

 

Then I get my embed url which I use in WebView Source property but I am not logged in. When I do login i see this report, but otherwise I can't. Where am I making a mistake/mistakes? 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello all, I found solution to this, so if anyone else is stuck you can check out link on stack overflow where I also posted this error: link 
It is listed as answer 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello all, I found solution to this, so if anyone else is stuck you can check out link on stack overflow where I also posted this error: link 
It is listed as answer 

V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could refer to this sample.

https://github.com/brminnick/PowerBISampleApp 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

hello and thanks for answering. That app is really confusing for me because I am begginer and I have no idea where anything goes in that app, and there is so little documentation for it. I will post my solution, but thatnks for help, maybe someone else will find it useful 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.