-
Describe the bug It follows the code for both types of authentication. To Reproduce --------------------------------------------------Set Authentication variables for SP authentication--------------------------------------------------client_id = 'Service Principal Client ID' --------------------------------------------------Get the access token via SP authentication--------------------------------------------------app = msal.ConfidentialClientApplication( result = app.acquire_token_for_client(scopes=scope) accessToken = result['access_token'] --------------------------------------------------Set local variables for User and Pwd Authentication--------------------------------------------------client_id = 'Registered App Client ID' --------------------------------------------------Get the access token via User and Pwd Authentication--------------------------------------------------app = msal.PublicClientApplication(client_id, authority=authority_url) -------------------------------------------------------------------------------------------------------------Check if a token was obtained, grab it and call the Power BI REST API, otherwise throw up the error message-------------------------------------------------------------------------------------------------------------if 'access_token' in result: accessToken = result['access_token'] print(accessToken) --------------------------------------------------Get the workspaces list--------------------------------------------------header = {'Content-Type': 'application/json', 'Authorization': f'Bearer {accessToken}'} workspacesId = [] for w in workspacesJson['value']: workspaces['id'] = workspacesId groupName = workspaces['name'][0] # forcing to choose the first workspace print('Got the workspace info, workspaceName:', groupName, ',workspaceId: ', groupId) -------------------------------------------------Get the reports list--------------------------------------------------header = {'Content-Type': 'application/json', 'Authorization': f'Bearer {accessToken}'} reportsId = [] for r in reportsJson['value']: reports['id'] = reportsId reportName = reports['name'][0] print('Got the report info, reportName:', reportName, ',reportEmbedUrl:', reportEmbedUrl) Expected behavior What you see instead **The MSAL Python version ** |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Sounds like you can successfully obtain an access token when you authenticated as a service principal, then MSAL already does its job. Whether that service principal can access a certain resource depends on its permission. You probably need to look into Power BI documents for that. BTW, next time when you paste your source code, you can wrap them inside "```python" and "```" (both in their own line), then they will be rendered readably. print("hello world") |
Beta Was this translation helpful? Give feedback.
-
Thank you @rayluo for your reply and support. I am not saying that I'm not able to retrieve the token. What I am saying is that the token that is returned is not functioning.
|
Beta Was this translation helpful? Give feedback.
-
Your code snippet seems right from the MSAL perspective. Perhaps the direction would be more on the "How to access Power BI api while authenticate via Service Principal". That is a domain knowledge that more likely be obtained from the Power BI community. In fact, a close look into the blog post "Power BI REST API with Python and Microsoft Authentication Library (MSAL)" you shared in your message, it even contains this bullet point (emphasis mine):
By the way, since MSAL 1.11, the confidential client also supports get a token via username/password. Looping in our PM @jmprieur to see whether he has any more input on this. |
Beta Was this translation helpful? Give feedback.
-
Dear @rayluo, I too have tried the official code documented in C# for the same purpose, and yet again a Token is received that is non-functional with respect to PowerBI Service-API access: In addition, the MSAL Library for .NET Microsoft.Identity.Client -Version 4.33.0 was made use of. Many thanks |
Beta Was this translation helpful? Give feedback.
-
@jmprieur , now we have stronger reason to pull you into this conversation. :-) Is there any intrinsic characteristic about Power BI and Service Principal that we would need to know? |
Beta Was this translation helpful? Give feedback.
-
Per offline investigation, @marossi10 's case can be resolved by configuring Power BI embed report's @AccidentalCitizen , you may also want to give it a shot. |
Beta Was this translation helpful? Give feedback.
-
@rayluo @AccidentalCitizen another important step is to generate the embedToken. The access token won't be enough. |
Beta Was this translation helpful? Give feedback.
@rayluo @AccidentalCitizen another important step is to generate the embedToken. The access token won't be enough.
The config parameter used to call powerbi.embed(embedDiv, config) will have therefore the following shape: