Forum Discussion
grant_type must be "password" and app level permissions
- 8 years ago
We use a service account that has access to PowerBI for this. We have MFA turned on almost all accounts, but off for service accounts.
It apears to be true that one needs the password grant type.
And for extra fun, the AAD library no longer supports it. "UserCredential" is no lnoger there.
So what you must do is issue a regular old HTTPS POST to the authority URL, and a body like this:
string authBody = $@" grant_type = password &resource ={WebUtility.UrlEncode(resourceString)} &username ={WebUtility.UrlEncode(username)} &password ={WebUtility.UrlEncode(password)} &client_id ={clientId} &client_secret={ WebUtility.UrlEncode(secret)}";With this information, becuase you're including a client secret, there will be no prompt necessary.
Good luck.
-e
Thank you Eric for your reply!!!
Yeah, after many tries, I believe it is true as the doc says, "Power BI permissions give an application the ability to take certain actions on a user's behalf. All permissions must be approved by a user in order to be valid." https://docs.microsoft.com/en-us/power-bi/developer/power-bi-permissions
Therefore grant_type: client_credentials does not work.
Here is a Postman screentshot of what to include to get the token:
Then you would get a token with scope in it.
"scp": "Capacity.Read.All Capacity.ReadWrite.All Content.Create Dashboard.Read.All Dashboard.ReadWrite.All Data.Alter_Any Datapool.Read.All Datapool.ReadWrite.All Dataset.Read.All Dataset.ReadWrite.All Group.Read Group.Read.All Metadata.View_Any Report.Read.All Report.ReadWrite.All Workspace.Read.All Workspace.ReadWrite.All".
Even if you grant the "Application Permissions" on the Azure App Registration page, I don't think it can bypass the "user context" requirement, which means, you must have user consent and use grant_type: password to get access token.
To achieve my goal, later I learned, to display the latest data for a push set, I just have to use TopN visual filter, and add a timestamp to my incoming data.
So in the end, I use LogicApp to pipe data to EventHub, and used Azure Stream Analytics to process further SQL queries, and then push data to PBI's stream dataset.
Learnt it from this tutorial https://www.pluralsight.com/courses/azure-power-bi-streaming