Guest User

Untitled

a guest
Oct 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. var getAccessToken = function {
  2.  
  3. return new Promise(function(resolve, reject) {
  4.  
  5. var url = 'https://login.microsoftonline.com/common/oauth2/token';
  6.  
  7. var username = // Username of PowerBI "pro" account - stored in config
  8. var password = // Password of PowerBI "pro" account - stored in config
  9. var clientId = // Applicaton ID of app registered via Azure Active Directory - stored in config
  10.  
  11. var headers = {
  12. 'Content-Type' : 'application/x-www-form-urlencoded'
  13. };
  14.  
  15. var formData = {
  16. grant_type:'password',
  17. client_id: clientId,
  18. resource:'https://analysis.windows.net/powerbi/api',
  19. scope:'openid',
  20. username:username,
  21. password:password
  22. };
  23.  
  24. request.post({
  25. url:url,
  26. form:formData,
  27. headers:headers
  28.  
  29. }, function(err, result, body) {
  30. if(err) return reject(err);
  31. var bodyObj = JSON.parse(body);
  32. resolve(bodyObj.access_token);
  33. })
  34. });
  35. }
Add Comment
Please, Sign In to add comment