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
Anonymous
Not applicable

Unable to generate Access Token with .NET Core

I'm trying to Embed Power BI Report using .NET Core Web Application and Angular. For this I used PowerBIEmbedded_AppOwnsData( .NET MVC) sample and successfully able to generate tokens and embed the report there

 

But in .NET Core Application as there is no AcquireTokenAsync method so I refered this Embed Power BI dashboard in ASP.Net core  which uses Resource Owner Password Credentials Grant flow and in the below coding using the same request body as I used earlier in PowerBIEmbedded_AppOwnsData(.NET) App.

 

 

 private async Task<OAuthResult> AuthenticateAsync()
        {
            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", ApplicationId),
                     new KeyValuePair<string,string>("client_secret", ApplicationSecret),
                     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();
                return JsonConvert.DeserializeObject<OAuthResult>(content);
            }

        }

 

 

But this time I am getting an error response which was succesful in .NET Sample

 

{
    "error": "invalid_grant",
    "error_description": "AADSTS50126: Invalid username or password.\r\nTrace ID: e4813657-d71a-480c-87a2-1140a49b6f00\r\nCorrelation ID: ba79a622-32e2-4a12-b7fd-65a21a99f378\r\nTimestamp: 2019-05-07 09:46:05Z",
    "error_codes": [
        50126
    ],
    "timestamp": "2019-05-07 09:46:05Z",
    "trace_id": "e4813657-d71a-480c-87a2-1140a49b6f00",
    "correlation_id": "ba79a622-32e2-4a12-b7fd-65a21a99f378"
}

Please Help

 

 

0 REPLIES 0

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

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.