title: Problem generating valid oauth2 token to access PowerBI APIs
body: <p><strong>The Setup :</strong> </p>
  
  <p>Am trying to access Azure PowerBI based APIs using console application since my company wants to <a href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/azure-pbie-pause-start" rel="nofollow noreferrer">Suspend/Resume</a> PBI capacity to optimize costing.</p>
  
  <p>Have been successful in accessing those apis as per official documentation <a href="https://docs.microsoft.com/en-us/rest/api/power-bi-embedded/capacities/suspend#code-try-0" rel="nofollow noreferrer">API Emulator Window</a>, it works by perfect as it just asks with a authentication window for username and password of my outlook account and it generates authentication token implicitly successful.</p>
  
  <p>When i tried to implement calling api from my console application which will be triggered automatically scheduled, there are ways to generate authentication token programmatically. Following are the methods i used to generate the same before accessing the PBI APIs.</p>
  
  <p><strong>Approach #1</strong> : <a href="https://stackoverflow.com/questions/53274859/get-authorization-code-for-azure-powerbi-capacity-for-powerbi-embedded">Generating token by using Azure Active Directory Authentication Libraries.</a>.</p>
  
  <p>This approach asks to add AAD authentication libraries via Nuget, upon adding the same and it goes unsuccessful as the method AcquireTokenAsync takes no parameters but tutorial specified 4 parameters to be feed into this method (function overloading missing?). So i couldnt generate token using this approach. Surely a library version problem but the <a href="https://docs.microsoft.com/en-us/azure/active-directory/azuread-dev/active-directory-authentication-libraries" rel="nofollow noreferrer">official MS documentation</a> didnt explain anything above versions available over same.</p>
  
  <p><strong>Approach #2:</strong> <a href="https://stackoverflow.com/questions/40843077/how-to-authorize-in-azure-active-directory-without-using-dialog/40844983#40844983">Authorize Active Directory without dialog box</a> StackOverflow Question with marked as answer<br>
  This approach upon calling HTTPResponseMessage, it gets hung up without going next line or catch statement.</p>
  
  <p><strong>Approach #3:</strong> Trying to emulate token generation using POSTMAN and using the generated token on my console app to check accessibility.</p>
  
  <p>This approach gives a successful token generation but when using the generated token in the console app, it says unauthorised token.</p>
  
  <p><strong>Doubt Part:</strong>
  Have generated ClientID, ClientSecretID and TenantID in Azure using AppRegisteration but dont know how this gets associated with PowerBI Service in azure. Do Azure Active Directory comes in place betweeen PBIService and AppRegisteration? Based on generated AppRegisteration details have tried to access this authentication api (<a href="https://login.microsoftonline.com/tenantId/oauth2/token" rel="nofollow noreferrer">https://login.microsoftonline.com/tenantId/oauth2/token</a>) to generate token. This is successfully generates a token but miserably getting failed with unauthorised access on PBI api.</p>
  
  <p>Am i badly missing something? will be helpful on what wrong about this concept of accessing PBI based API getting authenticated via console app. Asusual PBI community sites didnt help much.</p>