How to get PowerBI accesstoken using ADAL.JS

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 05:53:27

问题


I'm trying to use ADAL.js to authenticate against PowerBI in order to get an access_token and the embed_token needed to embed PowerBI reports/dashboards/tiles in a html/javascript-only "webpart". My adal-config looks like:

config = {
    instance: 'https://login.windows.net/common/oauth2/authorize/',
    tenant: 'tenant.onmicrosoft.com',
    clientId: '05xxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx',
    loginResource: "https://analysis.windows.net/powerbi/api",
    postLogoutRedirectUri: window.location.origin,
    cacheLocation: 'localStorage', 
};

But I can't seem to find any access-token etc in the user.profile I get. I am obviously missing something but what.. :) Any help would be much appriciated


回答1:


Looking at: https://community.powerbi.com/t5/Developer/get-Access-token-using-js/m-p/350294 and also this: https://community.powerbi.com/t5/Developer/How-to-Generate-Embed-Token-in-pure-JavaScript/td-p/350056

you can use ADAL.js to get the access token itself

window.config  = {
  instance: 'https://login.microsoftonline.com/',
  tenant: 'common', //COMMON OR YOUR TENANT ID

  clientId: 'XXXXX', //This is your client ID
  redirectUri: 'XXXXXX', //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;
    }
}


来源:https://stackoverflow.com/questions/48523851/how-to-get-powerbi-accesstoken-using-adal-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!