Not sure if I'm just missing something. Trying to get to know the REST API, and I can't get past a 403 error.
The goal is for the user to click sign in, and then to load a list of their datasets. Sample here:
https://dashbi-encore.azurewebsites.net
Code:
var ADAL = new AuthenticationContext({ instance: 'https://login.microsoftonline.com/', tenant: 'common', clientId: 'ee4d167d-3a52-4578-b2f6-fd6fb8efb84a', redirectUri: 'https://dashbi-encore.azurewebsites.net', callback: userSignedIn, popUp: true }); function signIn() { ADAL.login(); } function userSignedIn(err, token) { console.log('userSignedIn called'); if (!err) { showWelcomeMessage(); 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(); } else { console.error("error: " + err); } } function showWelcomeMessage() { var user = ADAL.getCachedUser(); var divWelcome = document.getElementById('WelcomeMessage'); divWelcome.innerHTML = "Welcome " + user.profile.name; }
I seem to do fine getting the token from AD - and I pass it through in the header of my API request as instructed - but it just won't take. I have correctly created my application and requested the proper permissions (tried via multiple different portals) .