Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
i-ivanov-09266
New Member

Power BI: 401 error when trying to acquire an access token (ConfidentialClientApplication.acquireTok

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 is 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

2 REPLIES 2
v-mengzhu-msft
Community Support
Community Support

Hi @i-ivanov-09266 ,

 

It seems like a network error, as the error message says. Can you access the following link successfully? Have you open firewall or proxy?

vmengzhumsft_0-1664766292618.png

You can use "developer tool" to check your error.

 

Best regards,

Community Support Team Selina zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi!

 

Yes, I can access the link in the browser. This is what appears:

iivanov09266_0-1664788327908.png

 

 

The error code I get when trying to acquire a token is 401 - unauthorized, which does not seem to be a network error, but a permission error. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors