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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
MAK89
Frequent Visitor

Cannot get PowerBI Access token

Here's the error I get while trying to get the access token.

 

{
"error": "invalid_grant",
"error_description": "AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\nTrace ID: a34fb8ab-1026-4120-9d50-623a848b1600\r\nCorrelation ID: cbe5596a-d438-4807-be82-36769aefafe7\r\nTimestamp: 2018-10-10 13:47:30Z",
"error_codes": [70002, 50126],
"timestamp": "2018-10-10 13:47:30Z",
"trace_id": "a34fb8ab-1026-4120-9d50-623a848b1600",
"correlation_id": "cbe5596a-d438-4807-be82-36769aefafe7"
}

 

I'm using ASP.NET Core to embed the power bi report.

 

Here's my code for reference:

 

 

private static async Task<OAuthResult> AuthenticateAsync()
        {
            var oauthEndpoint = new Uri(AuthorityUrl);

            using (var client = new HttpClient())
            {
                var result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
                {
            new KeyValuePair<string, string>("resource", ResourceUrl),
            new KeyValuePair<string, string>("client_id", ClientId),
            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);
            }
        }

        class OAuthResult
        {
            [JsonProperty("token_type")]
            public string TokenType { get; set; }
            [JsonProperty("scope")]
            public string Scope { get; set; }
            [JsonProperty("experies_in")]
            public int ExpiresIn { get; set; }
            [JsonProperty("ext_experies_in")]
            public int ExtExpiresIn { get; set; }
            [JsonProperty("experies_on")]
            public int ExpiresOn { get; set; }
            [JsonProperty("not_before")]
            public int NotBefore { get; set; }
            [JsonProperty("resource")]
            public Uri Resource { get; set; }
            [JsonProperty("access_token")]
            public string AccessToken { get; set; }
            [JsonProperty("refresh_token")]
            public string RefreshToken { get; set; }
        }

I'm using the same username and password and the same client ID for my MVC application and I get the token.  

2 REPLIES 2
TedPattison
Microsoft Employee
Microsoft Employee

Are you using a Azure AD application which is registered as a Native client as opposed to Web app / API. The Native client is the only type of that supports the Password credential flow. This might not be the issue but I thought I would call it out just in case.

 

 

Yes I'm using an Azure AD app registration of type "Native" in this case.  Also, I'm using .NET Core 2.0 app.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.