Hi,
We are working on Power BI Report embedding in .Net Core web app. We are facing issue while generating auth token for native Active Directory app registered on Azure. We can able to embed the Power Bi report in .Net 4.6 web app, but facing issue in .Net core web app.
To generate token we are using REST API and calling then using HTTPClient but this its returns error as "Invaliad credentials". I have triple checked the credentials and those are correct. We follow the example provide here to generate token.
Can you please provide any alteranative or solution or pointers to get auth token for Native ADD app using .Net core.
Regards,
Rohan
Hi Rohan,
Since we call the REST API directly, the "oauthEndpoint" is different. Please refer to the code below, which works in my test.
private static async Task<OAuthResult> AuthenticateAsync() { String clientId = "3a7c5ccc-***********5f"; String authorityUrl = "https://login.microsoftonline.com/{replace_with_your_tenant_id}/oauth2/token"; String resourceUrl = "https://analysis.windows.net/powerbi/api"; String userName = "da*****oft.com"; String password = "P***1"; 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); } }
1. Regarding the tenant ID, please refer to how-to-get-the-azure-account-tenant-id.
2. Get Azure AD access token, please refer to /azure/active-directory/develop/v1-protocols-oauth-code#use-the-authorization-code-to-request-an-acc....
Please understand that this link is provided “AS IS” with no warranties or guarantees of content changes, and confers no rights.
Best Regards,
Dale
User | Count |
---|---|
13 | |
4 | |
2 | |
2 | |
2 |