title: steps to integrate PowerBI report on Java application
body: <p>JavaScripts Required
      jquery.js
      powerbi.js</p>
  
  <ol>
  <li>Generate AAD token</li>
  </ol>
  
  <p>I assume that you have Native application built already and all required Power BI Access has been given.If not then refer steps A to C below.</p>
  
  <p>I used the steps mentioned on this link.I modified it a bit to reuse token till it get expired.Only after expiration,we will generate new token
  <a href="http://community.powerbi.com/t5/Developer/Rest-api-usage-with-Java/m-p/58514#M1841" rel="noreferrer">http://community.powerbi.com/t5/Developer/Rest-api-usage-with-Java/m-p/58514#M1841</a>
  This application will give AAD token for REST call received</p>
  
  <ol start="2">
  <li><p>Create DIV for Report On JSP page of application that need Report to be embeded </p>
  
  <p>div id="reportContainer" class="reportContainer" </p></li>
  <li><p>Get AAD token</p></li>
  </ol>
  
  <p>Make REST call to application developed at Step 1 get AAD token </p>
  
  <p>my aadToken object has 2 parameters accessToken and expiresAtStr</p>
  
  <pre><code>var aadToken={accessToken:' ',expiresAtStr: ''};
  
  function getAadAccessToken() {
      var deferred = $q.defer();
      $http.get('/MyPowerBIApp/REST/getAadToken/')
          .then(
          function (response) {
              deferred.resolve(response.data);
          },
          function(errResponse){
              console.error('Error while getting Aad Access Token');
              deferred.reject(errResponse);
          }
      );
      return deferred.promise;
  }   
  </code></pre>
  
  <p>After receiving aadToken from REST call, create Embed Configuration</p>
  
  <p>txtAccessToken is aad token from above.(aadToken.accessToken)
  txtEmbedUrl  is the report that needs to be embedded.
  It will be like <a href="https://app.powerbi.com/reportEmbed?reportId" rel="noreferrer">https://app.powerbi.com/reportEmbed?reportId</a>.......</p>
  
  <pre><code> var config= {
                       type: 'report',
                       tokenType: 0,//1:Embed,0:Aad
                       accessToken: txtAccessToken,
                       embedUrl: txtEmbedUrl,
                       permissions: 7,
                       viewMode: 0,
                       settings: {
                           filterPaneEnabled: false,
                           navContentPaneEnabled: false,
                           useCustomSaveAsDialog: false
                       }
                   };
  var $reportContainer = $('#reportContainer'); 
  var report = powerbi.embed($reportContainer.get(0), config); 
  </code></pre>
  
  <p>This will embed report on to the DIV</p>
  
  <hr>
  
  <p>Major mistakes occurred while trying to embed was on generating AAD Token.
  Make sure you have created Azure application and has given all required permissions to use Power BI APIs</p>
  
  <p>A. Create Native App as mentioned here:
  <a href="https://docs.microsoft.com/en-us/power-bi/developer/walkthrough-push-data-register-app-with-azure-ad" rel="noreferrer">https://docs.microsoft.com/en-us/power-bi/developer/walkthrough-push-data-register-app-with-azure-ad</a></p>
  
  <p>B. Go to Azure Active Directory-> App registrations
  Click on Your Application :
  Application ID value that you see here is the clientId value that you will use for AAD Token generation mentioned on step 1</p>
  
  <p>Please refer below code: </p>
  
  <pre><code>AuthenticationResult authResult = authenticationContext.acquireToken(
              resourceId,
              clientId,
              username,
              password,
              null
      ).get();
  </code></pre>
  
  <p>C. Go To Azure Active Directory-> App registrations ->Settings ->Required permissions</p>
  
  <p>Make sure that Power BI Service (Power BI) is under the API and all required permissions are given.Below are few of the permissions
  View users Groups
  View All Reports
  View All Dashboards(Preview)</p>
  
  <p>If all these steps are done,you should be able to embed the report with the token received.
  Please check and let me know if I had missed any steps or there will be any issues on this approach.</p>
  
  <p>Also Make sure that the username that will be used to generate AAD Token is having access(MemberOf) PowerBI workspace where the Report resides</p>