Refreshing OAuth2 credentials for Power BI, expiring token

Describe the problem/error/question

  • I have setup a OAuth2 credentials to connect to Power BI service

  • I have created and provided the necessary permission to a registered app in Azure AD

  • When creating the OAuth2 credential, I have provided the necessary scope for connecting to Power BI and included access_type=offline in the Auth URI Query Parameter

  • Once the credentials are initially connected, the workflow works fine

  • However, once the token expires, the token does not refresh

What is the error message (if any)?

  • 403 - "{\"error\":{\"code\":\"TokenExpired\",\"message\":\"Access token has expired, resubmit with a new access token\"}}"
    
    

Please share your workflow

:light_bulb: Double-click a node to see its settings, or paste this workflow’s code into n8n to import it

Credential setup

Information on your n8n setup

  • n8n version: Version 2.2.4

  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud

  • Operating system: MacOS

I’d blur out the call-back URL :wink:

As for the token. When I’m workign with Business Central I get a valid-time in seconds as part of the response. If the token expires, or is close to expiring, it’s relatively easy to renew it using a generic HTTP request:

Powershell example (may work differently if you need a different grant type):

access token

$body = @{
grant_type=“client_credentials”
scope=$scope
client_id=$ClientID
client_secret=$ClientSecret
}

$oauth = Invoke-RestMethod -Method Post -Uri https://tokenurlfrommicrosoft -Body $body -ContentType “application/x-www-form-urlencoded”

1 Like

Whoops, thanks @Galactic_pawns - more blurring applied!

I had been trying the HTTP request way for a while without success, however today it’s worked!

Appreciate your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.