I'm using this code to login in AAD
function login(network){ // By defining response type to code, the OAuth flow that will return a refresh token to be used to refresh the access token // However this will require the oauth_proxy server //Foi feita uma modificação dentro de login ou hello (procurar /organizations) para enviar o <<<<-------------------------<<<< hello(network).login({display: 'popup'}, log).then(function(response) { log('You are signed in to AAD'); _sessionData = response; // Change button to Sign Out var authButton = document.getElementById('auth'); authButton.innerHTML = 'logout'; authButton.setAttribute('onclick', 'logout("aad");'); }, function(e) { alert('Signin error: ' + e.error.message); }); } function logout(network){ // Removes all sessions, need to call AAD endpoint to do full logout hello(network).logout({force: true}, log).then(function() { log('You have Signed Out of AAD'); // Change button to Sign in var authButton = document.getElementById('auth'); authButton.innerHTML = "Login AAD"; authButton.setAttribute('onclick', 'login("aad");'); }, function(e) { alert('Sign out error: ' + e.error.message); }); }
hello.init({ aad : '16969bc9-xxxx-7290' },{ redirect_uri: 'http://localhost/AADeDB/redirect.html', resuorce: 'https://analysis.windows.net/powerbi.api', scope: 'user.read' }); function log(s){ document.body.querySelector('.response').appendChild(document.createTextNode("\n\n" + JSON.stringify(s, true, 2))); }
It return:
{ "network": "aad", "authResponse": { "access_token": "eyJ0eXAiOiJKV1QiLCJub25jZSI6...", "token_type": "Bearer", "expires_in": 3599, "scope": "user.read", "state": "", "session_state": "1b3cb0a4-8d36-4dd6-93ce-121e9e38e13f", "client_id": "16969bc9-xxx-ee7290", "network": "aad", "display": "popup", "redirect_uri": "http://localhost/AADeDB/redirect.html", "expires": 1517424596.387 } } "You are signed in to AAD"
But using this access token atatching at the header of the message:
var request = new XMLHttpRequest(); request.open('GET', 'https://api.powerbi.com/v1.0/myorg/dashboards'); var s = 'Bearer '+_sessionData.authResponse.access_token; request.setRequestHeader('Authorization', 'Bearer '+s); request.onreadystatechange = function () { if (this.readyState === 4) { console.log('Status:', this.status); console.log('Headers:', this.getAllResponseHeaders()); console.log('Body:', this.responseText); } }; request.send();
I got this at the console:
GET https://api.powerbi.com/v1.0/myorg/dashboards 403 (Forbidden) Status: 403 Headers: Body:
Any Idea of what can I do?
Im using the libs: hello.js aad.js jquery.js and powerbi.js.
I need to get the configurations (embedToken) to set the embedUrl and show the dashboard.
Thx