To get Power BI access token by grand type password, use the bellow code
public async Task<OAuthResultDto> GetAccessTokenAsync()
{
var oauthEndpoint = new Uri("https://login.microsoftonline.com/common/oauth2/token");
using (var client = new HttpClient())
{
var result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"),
new KeyValuePair<string, string>("client_id", "1638c1dd-xxxx-4444-xxxx-xxxx4444xxxx"),
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", "username"),
new KeyValuePair<string, string>("password", "password"),
new KeyValuePair<string, string>("scope", "openid")
}));
var content = await result.Content.ReadAsStringAsync();
var deserilized = JsonConvert.DeserializeObject<OAuthResult>(content);
return deserilized;
}
}
Details about above method:
oauthEndpoint : Authorization will happen here
resource: Resource URI
client_id: Client Id or Application Id, which can be obtain from Azure Active directory by creating an application.
grant_type: It is type of authentication
username: User name register with Power BI
password: User Password
scope: Scope
OAuthResult:
public class OAuthResult
{
[JsonProperty("token_type")]
public string TokenType { get; set; }
[JsonProperty("scope")]
public string Scope { get; set; }
[JsonProperty("expires_in")]
public int ExpiresIn { get; set; }
[JsonProperty("ext_expires_in")]
public int ExtExpiresIn { get; set; }
[JsonProperty("expires_on")]
public int ExpiresOn { get; set; }
[JsonProperty("not_before")]
public int NotBefore { get; set; }
[JsonProperty("resource")]
public string Resource { get; set; }
[JsonProperty("access_token")]
public string AccessToken { get; set; }
[JsonProperty("refresh_token")]
public string RefreshToken { get; set; }
[JsonProperty("id_token")]
public string TokenId { get; set; }
}
The solution that I found recommended online for ASP.Net core is to use a tag helper however now that the Power BI Embedded and Power BI service have converged with the new arrival of Power BI Premium I dont think think this solutions is possible due to the depencency on token authentication for the App Hosted data.
Hello, great work. I really appeaciate the information you are providing through your website, i have alwasy find it helpful. Keep up the nice work.
I’m really enjoying the theme/design of your weblog. Do you ever run into any web browser compatibility problems? A couple of my blog visitors have complained about my website not working correctly in Explorer but looks great in Firefox. Do you have any ideas to help fix this problem?
I really like your writing style, good info, thanks for posting :D. “Kennedy cooked the soup that Johnson had to eat.” by Konrad Adenauer.
Attractive section of content. I just stumbled upon your website and in accession capital to assert that I acquire actually enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently fast.
Magnificent beat ! I wish to apprentice while you amend your web site, how can i subscribe for a weblog website? The account helped me a acceptable deal. I have been tiny bit familiar of this your broadcast provided brilliant transparent concept|
Wow, awesome blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is wonderful, let alone the content!|
Hello my loved one! I wish to say that this article is awesome, nice written and come with almost all significant infos. I’d like to look more posts like this .|
Hello! This post could not be written any better! Reading through this post reminds me of my old room mate! He always kept chatting about this. I will forward this article to him. Fairly certain he will have a good read. Thank you for sharing!|
Hey there, I think your website might be having browser compatibility issues. When I look at your blog site in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, amazing blog!
I’m no longer certain the place you’re getting your information, however good topic. I needs to spend a while studying more or figuring out more. Thanks for fantastic information I was looking for this information for my mission.|
If some one needs to be updated with newest technologies afterward he must be pay a quick visit this web page and be up to date daily.|
I’m not sure exactly why but this blog is loading incredibly slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later on and see if the problem still exists.|
Greetings from Carolina! I’m bored at work so I decided to browse your website on my iphone during lunch break. I enjoy the info you present here and can’t wait to take a look when I get home. I’m shocked at how fast your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyways, fantastic blog!|
Undeniably consider that which you said. Your favourite reason seemed
to be at the internet the simplest factor to consider of. I say to you,
I definitely get irked even as other people
consider concerns that they plainly do not understand about.
You managed to hit the nail upon the highest and outlined out the whole thing
with no need side effect , folks could take a signal.
Will probably be again to get more. Thank you
Excellent blog here! Also your website loads up very fast! What web host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as fast as yours lol|