<?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: get Access token using js in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/404159#M12056</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I would like to get the accesToken of a client.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I have&amp;nbsp;his&amp;nbsp;username,&amp;nbsp;his password and the link for an emebbed report.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;this is my link : &lt;A href="https://app.powerbi.com/groups/me/reports/" target="_blank"&gt;https://app.powerbi.com/groups/me/reports/&lt;/A&gt;&lt;EM&gt;my-report-id&lt;/EM&gt;?ctid=&lt;EM&gt;my-client-id&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;So with all these informations, can i get the access token so i can emb&lt;/SPAN&gt;&lt;SPAN class=""&gt;ed the report on my own ?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I tried to use the javascript's code of "&lt;A title="" href="https://community.powerbi.com/t5/user/viewprofilepage/user-id/11689" target="_self"&gt;v-ljerr-msft&lt;/A&gt;" but it doesn't work with my clientId.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I get this error :&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="outer"&gt;&lt;DIV class="middle"&gt;&lt;DIV class="inner wide"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class="row text-body"&gt;AADSTS70001: Application with identifier&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;my-client-id&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;was not found in the directory&amp;nbsp;&lt;EM&gt;my-directory&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;Can someone help me ?&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;Geoffrey&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="footer"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 25 Apr 2018 12:09:57 GMT</pubDate>
    <dc:creator>gmisslinwigo</dc:creator>
    <dc:date>2018-04-25T12:09:57Z</dc:date>
    <item>
      <title>get Access token using js</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/350294#M10396</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I was just wondering if it's possible to get access token using js?? If yes would be possible show me sample&lt;/P&gt;&lt;PRE&gt;var getAccessToken = function () {

    return new Promise(function (resolve, reject) {

        var url = 'https://login.microsoftonline.com/common/oauth2/token';

        var username = 'login'; // Username of PowerBI "pro" account - stored in config
        var password = 'password'; // Password of PowerBI "pro" account - stored in config
        var clientId ='id' // Applicaton ID of app registered via Azure Active Directory - stored in config

    var headers = {
            'Content-Type': 'application/x-www-form-urlencoded'
        };

        var formData = {
            grant_type: 'password',
            client_id: clientId,
            resource: 'https://analysis.windows.net/powerbi/api',
            scope: 'openid',
            username: username,
            password: password
        };

        console.log(request.post)

        request.post({
            url: url,
            form: formData,
            headers: headers

        }, function (err, result, body) {
            console.log(result);
        })
    });
}&lt;/PRE&gt;&lt;P&gt;This what I tried to make but I alsway has problem&lt;/P&gt;&lt;P&gt;&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at &lt;A href="https://login.microsoftonline.com/common/oauth2/token" target="_blank"&gt;https://login.microsoftonline.com/common/oauth2/token&lt;/A&gt;. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="message-body-wrapper"&gt;I tried to add it on head for my post query but it's still doesnt work&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 05:41:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/350294#M10396</guid>
      <dc:creator>oflok000</dc:creator>
      <dc:date>2018-02-02T05:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: get Access token using js</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/352093#M10472</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/53438"&gt;@oflok000&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on my research, you may need to use&amp;nbsp;&lt;SPAN&gt;the ADAL.js to&amp;nbsp;get the access_token in pure js code. &lt;A href="https://community.powerbi.com/t5/Developer/How-to-Generate-Embed-Token-in-pure-JavaScript/td-p/350056" target="_self"&gt;Here&lt;/A&gt; is a similar thread for your reference.&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.fabric.microsoft.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Sample Code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="utf-8" /&amp;gt;
        &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
		
       &amp;lt;script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.12/js/adal.min.js"&amp;gt;&amp;lt;/script&amp;gt;
	   &amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
			 &amp;lt;script&amp;gt;
			  window.config  = {
				  instance: 'https://login.microsoftonline.com/',
				  tenant: 'common', //COMMON OR YOUR TENANT ID

				  clientId: '49df1bc7-db68-4fb4-91c0-6d93f770d1a4', //This is your client ID
				  redirectUri: 'https://login.live.com/oauth20_desktop.srf', //This is your redirect URI

				  callback: userSignedIn,
				  popUp: true
			  };
			  
			  var ADAL = new AuthenticationContext(config);

				function signIn() {
				      ADAL.login();
				  }
				
				  function userSignedIn(err, token) {
				      console.log('userSignedIn called');
				      if (!err) {
                				          
                  showWelcomeMessage();
				  
				  ADAL.acquireToken("https://analysis.windows.net/powerbi/api", function (error, token) {

            // Handle ADAL Error
            if (error || !token) {
                printErrorMessage('ADAL Error Occurred: ' + error);
                return;
            }

            // Get TodoList Data
            $.ajax({
                type: "GET",
                url: "https://api.powerbi.com/v1.0/myorg/datasets",
                headers: {
                    'Authorization': 'Bearer ' + token,
                },
            }).done(function (data) {

               
                console.log(data);

                    

                // Update the UI
                $loading.hide();
               

            }).fail(function () {
                printErrorMessage('Error getting todo list data')
            }).always(function () {

                // Register Handlers for Buttons in Data Table
                registerDataClickHandlers();
            });
        });
				      }
				      else {
				          console.error("error: " + err);
				      }
				  }
				  
				  
				  
				  
				  function getDataSets(){
				   
						      
                  var trythis = "Bearer " + token;
    							var request = new XMLHttpRequest();

                  request.open('GET', 'https://api.powerbi.com/v1.0/myorg/datasets');
                  
                  request.setRequestHeader('Authorization', trythis);
                  
                  request.onreadystatechange = function () {
                    if (this.readyState === 4) {
                      console.log('Status:', this.status);
                      console.log('Body:', this.responseText);
                    }
                  };
                  
                  request.send();
				  
				  
				  }
				  
				  
				  
				
				  function showWelcomeMessage() {
				      var user = ADAL.getCachedUser();
				      var divWelcome = document.getElementById('WelcomeMessage');
				      divWelcome.innerHTML = "Welcome " + user.profile.name;
				  }
        &amp;lt;/script&amp;gt;

    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        
        
			 &amp;lt;button id="SignIn" onclick="signIn()"&amp;gt;Sign In&amp;lt;/button&amp;gt;
			 &amp;lt;h4 id="WelcomeMessage"&amp;gt;&amp;lt;/h4&amp;gt;	
             
      
             
             
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 02:48:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/352093#M10472</guid>
      <dc:creator>v-ljerr-msft</dc:creator>
      <dc:date>2018-02-06T02:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: get Access token using js</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/404159#M12056</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I would like to get the accesToken of a client.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I have&amp;nbsp;his&amp;nbsp;username,&amp;nbsp;his password and the link for an emebbed report.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;this is my link : &lt;A href="https://app.powerbi.com/groups/me/reports/" target="_blank"&gt;https://app.powerbi.com/groups/me/reports/&lt;/A&gt;&lt;EM&gt;my-report-id&lt;/EM&gt;?ctid=&lt;EM&gt;my-client-id&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;So with all these informations, can i get the access token so i can emb&lt;/SPAN&gt;&lt;SPAN class=""&gt;ed the report on my own ?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I tried to use the javascript's code of "&lt;A title="" href="https://community.powerbi.com/t5/user/viewprofilepage/user-id/11689" target="_self"&gt;v-ljerr-msft&lt;/A&gt;" but it doesn't work with my clientId.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I get this error :&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="outer"&gt;&lt;DIV class="middle"&gt;&lt;DIV class="inner wide"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class="row text-body"&gt;AADSTS70001: Application with identifier&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;my-client-id&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;was not found in the directory&amp;nbsp;&lt;EM&gt;my-directory&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;Can someone help me ?&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="row text-body stack-trace text-caption"&gt;Geoffrey&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="footer"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 25 Apr 2018 12:09:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/404159#M12056</guid>
      <dc:creator>gmisslinwigo</dc:creator>
      <dc:date>2018-04-25T12:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: get Access token using js</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/407306#M12142</link>
      <description>&lt;P&gt;I'm trying to get this flow working myself, so take my advice with a grain of salt, but it appears you have a wrong combination of tenant ID and client ID. Try using just "common" instead of the tenant ID&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 13:49:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/407306#M12142</guid>
      <dc:creator>Christy</dc:creator>
      <dc:date>2018-04-30T13:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: get Access token using js</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/1595020#M27210</link>
      <description>&lt;P&gt;This looks like not working anymore. Does anyone have a solution to use msal or adal in order to connect to powerbi api ? How can I get a powerbi token like I would do for OneDrive ?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 17:32:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/1595020#M27210</guid>
      <dc:creator>victordavid</dc:creator>
      <dc:date>2021-01-12T17:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: get Access token using js</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/1647967#M27697</link>
      <description>&lt;P&gt;Were you able to find any solution for generating embed token using javascript?&lt;/P&gt;&lt;P&gt;If yes please post here, I am looking for the same thing.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 13:22:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/get-Access-token-using-js/m-p/1647967#M27697</guid>
      <dc:creator>nnm</dc:creator>
      <dc:date>2021-02-05T13:22:07Z</dc:date>
    </item>
  </channel>
</rss>

