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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Advocate I
Advocate I

authentication issue when embedding in aspnetcore

building on this previous post:

(Embed Power BI dashboard in ASP.Net core)


on this line:

                string content = await result.Content.ReadAsStringAsync();

the content im receiving back in AuthenticateAsync is this (only a portion):

"\r\n\r\n<!DOCTYPE html>\r\n<html dir=\"ltr\" class=\"\" lang=\"en\">\r\n<head>\r\n    <title>Sign in to your account</title>\r\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes\">\r\n    <meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n    <meta http-equiv=\"Expires\" content=\"-1\">\r\n    <meta name=\"PageID\" content=\"ConvergedSignIn\" />\r\n    <meta name=\"SiteID\" content=\"\" />\r\n    <meta name=\"ReqLC\" content=\"1033\" />\r\n    <meta name=\"LocLC\" content=\"en-US\" />\r\n\r\n        <noscript>\r\n            <meta http-equiv=\"Refresh\" content=\"0; URL=\" />\r\n        </noscript>\r\n        <link rel=\"shortcut icon\" href=\"\" />\r\n    \r\n    "


which needless to say is not JSON and certainly isnt a token!

can anyone tell me whats going on here? and what is my next step to getting a tooken?


here is the rendered outut returned from the function:




ps - i know my credentials work 

because i built the example in the standard .net version (ie minus the mods for aspnetcore)

and they totally worked




endpoints have changed:

AuthorityUrl = "


in one of the examples it was 

AuthorityUrl = "

which is what i had in my code


hope this helps




View solution in original post

Microsoft Employee
Microsoft Employee

Follow the steps mentioned in the thread below:

Embed Power BI Report in Asp.Net Core Website


 The workaround here is to compose the HTTP request directly.

Not sure how the code in your tests works,the content you received should be the authentication page from "", which is used to finish the authentication and generate the token.

The workable content should be the content returned from "".





hey michael 

thx for the response

but if you read my orig post

i stated i had already followed that post

and the result im getting is the result i posted

(adjusted so as to render the non-json result i am getting)


for clarity here is my current code:

       public async Task<ActionResult> index() {
            var result = new EmbedConfig { Username = Username };
            var error = GetWebConfigErrors();
            if (error != null)
                result.ErrorMessage = error;
                return View(result);

            var authenticationResult = await AuthenticateAsync();
            if (authenticationResult == null) {
                result.ErrorMessage = "Authentication Failed.";
                return View(result);
                return View(new connectVM(
                                isJson(authenticationResult) ? JsonConvert.DeserializeObject<string>(authenticationResult) : authenticationResult));

            //var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

        //.private static async Task<OAuthResult> AuthenticateAsync()
        // JsonConvert.DeserializeObject<OAuthResult>(authenticationResult) 
        private static async Task<string> AuthenticateAsync()
            Uri oauthEndpoint = new Uri(AuthorityUrl);
            using (HttpClient client = new HttpClient())
                HttpResponseMessage 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"),

                string content = await result.Content.ReadAsStringAsync();
                return content.ToString();



ive tried logging in directly through browser url

here is the url im using:


does the url at least look correct for the non-sensitive info?

still getting the sign in box

I'm having the exactly same issue, with the same code. Have also tried to get the token using Postman.

Always getting the Sign in page as response.


Here is the request:

POST /common/oauth2/authorize/ HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache



endpoints have changed:

AuthorityUrl = "


in one of the examples it was 

AuthorityUrl = "

which is what i had in my code


hope this helps




Thank you! Was the endpoint 🙂

Helpful resources

July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.