I’m having issues with the access token expiring when using the ManagementClient from the node-auth0 library. Looking at the code on GitHub, it seems like the ManagementClient should automatically get an access token through the TokenProviderMiddleware, including when the current access token expires.
I expect that each client instance should have a fresh access token. Strangely, I only hit the ManagementApiError: Expired token received for JSON Web Token validation error when trying to access users or roles but not invites.
Can you please help me understand what the issue might be?
The error you experience happens when the access token being used has expired. I suggest referring to this related community post that addresses this issue.
Essentially, you will want to verify the exp claim of your Management API access token is still valid:
Copy the generated Management API token from your code,
Paste the token on https://jwt.io/ and copy exp value in the payload
Let me also mention that you might hit the capacity for your monthly M2M authentication calls if you issue a new access token for every request. In general, you should cache the access token and renew it only once it has expired.
I then pass this token into the ManagementClient instead of relying on it internally fetching an access token, which looks to have fixed my issue. The IGNORE_CACHE headers are probably relevant; I had similar issues previously where my Management API request responses were getting cached.
I’m also now checking the expiration to ensure I’m not requesting a new token before the current one has expired, thanks for the callout!
My previous confusion was due to the fact that the expired token error was only being hit when I was trying to fetch users / roles, but not invites. I’d assume that if the access token is expired, it should appear expired to all endpoints (and likewise for valid access tokens).
Regardless, my issue is now resolved, thanks again!