<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Embedded Javascript (angular4) unable to get bearer token from Http Post - Error: CORs/[AADSTS90 in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/407944#M12151</link>
    <description>&lt;P&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Any help is greatly appreicated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;Christy&lt;/P&gt;</description>
    <pubDate>Tue, 01 May 2018 10:29:24 GMT</pubDate>
    <dc:creator>Christy</dc:creator>
    <dc:date>2018-05-01T10:29:24Z</dc:date>
    <item>
      <title>Embedded Javascript (angular4) unable to get bearer token from Http Post - Error: CORs/[AADSTS90014]</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/405281#M12087</link>
      <description>&lt;P&gt;Hello All;&lt;BR /&gt;&lt;BR /&gt;I have been trying for a while to get an embedded solution to work, as a proof of concept. But I am struggling with the Http requests.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is trying to follow the "App owns data" "example".&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embed-sample-for-customers" target="_self"&gt;https://docs.microsoft.com/en-us/power-bi/developer/embed-sample-for-customers&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I have created a Native application. I have given it the correct permissions, I used a global admin account, and I granted permissions within Azure Portal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following method works fine within PostMan (ie all the correct information&amp;nbsp;is given).&lt;A href=" https://community.powerbi.com/t5/Developer/How-To-Get-embed-token-using-Get-Post-only/td-p/294475" target="_self"&gt; https://community.powerbi.com/t5/Developer/How-To-Get-embed-token-using-Get-Post-only/td-p/294475&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However it fails when I try to call the first request (&lt;EM&gt;/oauth2/token&lt;/EM&gt;) with Javascript. All parameters are&amp;nbsp;identical, I have double and triple checked them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is as follows:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;getAccessToken(Password): string{
    const url = "https://login.windows.net/{tenantID}/oauth2/token";
    const headers = new HttpHeaders( {
        "Content-Type": "application/x-www-form-urlencoded"
    });
    const requestBody = {
        "grant_type": "password",
        "scope": "openid",
        "resource": "https://analysis.windows.net/powerbi/api",
        "client_id": this.getClientID(),
        "username": this.getUsername(),
        "password": Password
    }
    var accessTokenRequestReponse = this.httpClient.post(url, requestBody, {headers: headers}).subscribe(
        (reponse) =&amp;gt; {
            console.log(reponse)
            console.log(reponse['access_token'])
        },
        (error) =&amp;gt; {console.log(error)}
    )
    return("");
}&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have tried this endpoint with variations of the url, ie&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;https://login.windows.net/{tenantID}/oauth2/v2.0/token
https://login.windows.net/common/oauth2/v2.0/token
https://login.windows.net/{tenantID}/oauth2/token
https://login.windows.net/common/oauth2/token
https://login.microsoftonline.com/common/oauth2/token
https://login.microsoftonline.com/{tenantID}/oauth2/token&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;All of these are the same, they fail in JS, yet work in postman.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Initially the error was CORs. However I spun up a website on Azure, and put a build there and the issue persisted (ie not due to localhost). I had listed all urls (http:localhost:4200/powerBI&amp;nbsp;and &lt;A href="https://mywebsite.azure.net" target="_blank"&gt;https://mywebsite.azure.net&lt;/A&gt;) in the redirect section of the azure native app. I also set the allow implicit flow to true, in the manifest.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I used the following chrome extension&amp;nbsp;to allows CORs requests.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;A href="https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en" target="_self"&gt;https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;I found this on one of the posts on this forum, but I currently cant re-find it.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Once this is active to allow the CORs requests, I get a 400 (Bad request) error on my request.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I get the following information in the error:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;error:"invalid_request"
error_codes:[90014]
error_description:"AADSTS90014: The request body must contain the following parameter: 'grant_type'.
↵Trace ID: c4ce24c7-{...}d00
↵Correlation ID: 21a2c8d0-{...}87
↵Timestamp: 2018-04-26 {...}"&lt;/PRE&gt;&lt;SPAN class="name"&gt;When I examine this in the Network section of chrome, I find that the call has "grant_type" in it&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="name"&gt;Request Headers:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 260
Content-Type: application/x-www-form-urlencoded
Host: login.windows.net
Origin: http://evil.com/ #Note this is from that chrome extenstion
Referer: http://localhost:4200/powerBI
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Form Data:&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;{
  "grant_type":"password",
  "scope":"openid",
  "resource":"https://analysis.windows.net/powerbi/api",
  "client_id":"{clientID}",
  "username":"{username}@{tenant}.onmicrosoft.com",
  "password":"{password}",
  "tenant":"{tenant}.onmicrosoft.com"
}: &lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I believe this is meant to be the implicit flow&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;A href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-dev-understanding-oauth2-implicit-grant" target="_self"&gt;https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-dev-understanding-oauth2-implicit-grant&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;but I cant find anything on the documentation page on this call, and the other pages all seem to revolve around redirecting the user to mircosoft login page, and then redirecting back to the application, which defeats the goal of the "App owns data" as I want to display to non powerBI users.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Apologies for the long post. And many thanks to anyone who read it/has any advice.&lt;BR /&gt;&lt;BR /&gt;Kind Regards&lt;BR /&gt;Christy&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 26 Apr 2018 15:04:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/405281#M12087</guid>
      <dc:creator>Christy</dc:creator>
      <dc:date>2018-04-26T15:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Embedded Javascript (angular4) unable to get bearer token from Http Post - Error: CORs/[AADSTS90</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/406591#M12122</link>
      <description>&lt;P&gt;I will do some further research on this part.&lt;/P&gt;&lt;P&gt;There might be some time delay before I could response with any helpful points.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Sun, 29 Apr 2018 01:07:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/406591#M12122</guid>
      <dc:creator>v-micsh-msft</dc:creator>
      <dc:date>2018-04-29T01:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Embedded Javascript (angular4) unable to get bearer token from Http Post - Error: CORs/[AADSTS90</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/407944#M12151</link>
      <description>&lt;P&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Any help is greatly appreicated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;Christy&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 10:29:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/407944#M12151</guid>
      <dc:creator>Christy</dc:creator>
      <dc:date>2018-05-01T10:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Embedded Javascript (angular4) unable to get bearer token from Http Post - Error: CORs/[AADSTS90</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/458487#M14119</link>
      <description>&lt;P&gt;Hi Christy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you resolve your issue ?&lt;/P&gt;&lt;P&gt;Because we are stuck at the same point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nuno.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 08:00:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embedded-Javascript-angular4-unable-to-get-bearer-token-from/m-p/458487#M14119</guid>
      <dc:creator>nuno1977</dc:creator>
      <dc:date>2018-07-10T08:00:09Z</dc:date>
    </item>
  </channel>
</rss>

