0

Code (basically the same as the sample application in the Azure tutorial for Power BI embedded):

    private async getAccessToken() {
        const clientApplication = new msal.ConfidentialClientApplication({
            auth: {
                clientId: config.authClientID,
                authority: `https://login.microsoftonline.com/${config.authTenantID}`,
                clientSecret: config.authClientSecret,
            }
        });

        return await clientApplication.acquireTokenByClientCredential({
            scopes: ['https://analysis.windows.net/powerbi/api/.default'],
        });
    }

I have verified that the following parameters are correct:

  • config.authClientID
  • config.authTenantID
  • config.authClientSecret

I also have:

  • Granted all possible Power BI Service permissions to my Service Principal (in the Azure App Registration).
  • Granted access for my Service Principal in the Power BI admin portal (through a security group).

Here's the error I get when running this function:

network_error: Network request failed. Please check network trace to determine root cause. | Fetch client threw: Error: HTTP status code 401 | Attempted to reach: https://login.microsoftonline.com/{my tenant id}/oauth2/v2.0/token

What could I be doing wrong?

Thanks in advance

  • The error says that you can't reach that url. Do you have any firewall rules that prevents you from reaching https://login.microsoftonline.com ? – abaci Sep 29 '22 at 11:23
  • @abaci The error says that I am not authorized. As per [this answer](https://stackoverflow.com/a/6937030/7162167): "Receiving a 401 response is the server telling you, “you aren’t authenticated–either not authenticated at all or authenticated incorrectly–but please reauthenticate and try again.”". I do not have any firewall rules preventing me from reaching login.microsoftonline.com. – ivaylo_ivanov Sep 29 '22 at 12:07
  • Try to generate token with **same parameters** via **[Postman](https://i.imgur.com/FZ8O0vR.png)** and check whether you are getting token or not. – Sridevi Oct 07 '22 at 07:45

0 Answers0