Client-credentials don't work for powerBI REST API

后端 未结 1 829
误落风尘
误落风尘 2020-12-16 09:07

I\'m trying to implement the daemon authentication flow. The following post request returns me an access token with the right scope:

p_url = \'https://login.         


        
相关标签:
1条回答
  • 2020-12-16 09:28

    Your flow is a bit short. REST call for datasets seems OK, but as far as I know, you have to request the access token by authorization code, not client credentials alone.

    1) Get authorization code

    Depends on your flow, for website it will be received during logon process or call to /oauth2/authorize with { 'response_type':'code }

    2) Get access token

    With authorization code in a variable, you have to modify your request to include to authorization code, like this (grant_type and code fields are altered):

    p_url = 'https://login.microsoftonline.com/' + 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' + '/oauth2/token'
    data = { 'grant_type':'authorization_code',
         'client_id': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
         'client_secret': 'L------------------------------------------=',
         'code': authorizationCodeForSingedInUser,
         'resource':'https://analysis.windows.net/powerbi/api' }
    r = requests.post(url=p_url, data=data)
    

    Basically saying, you have to have a user account that accesses the Power BI resource. Your website (clientid + secret) are not authorized by itself. There must be a user involved.

    What's more, afaik only "organization account" users can access power bi.

    To be explicit and underline the main cause in this thread, post and comments: Power BI REST API can only be used via User with credentials with Organizational Account and be already signed in (activated) Power BI on Power BI portal. You can check if REST Api will work by checking if this user is able to use Power BI portal manually.

    0 讨论(0)
提交回复
热议问题