Auth0-js Management getUser returning 401 Invalid Token when using JWT idToken

I’ve attempted to get the user’s username by accessing the user management api.

My webAuth init looks like:

this.webAuth = new auth0.WebAuth({
  audience: 'https://' + config.auth0.domain + '/userinfo',
  clientID: config.auth0.clientId,
  domain: config.auth0.domain,
  redirectUri: config.auth0.redirectUri,
  responseType: 'token id_token',
  scope: 'openid profile email'
});

My management initialization looks like:

this.mgmt = new auth0.Management({
domain: config.auth0.domain,
token: accessToken
})

The “accessToken” being used is the idToken value pulled from the user. I’ve searched around and am seeing conflicted thoughts on using the idToken, and that the accessToken (an opaque string) is not the access token.

idToken looks like expected JWT format. So I’m not sure what I’m missing.

Hi @rejon,

Welcome to the Auth0 Community Forum!

Thanks for reaching out. The id_token is not going to be used for access the management API.

I will also point you to this FAQ because it looks like you are trying to access the management API from a SPA which has some special limitations due to it’s exposed nature.

Please let me know if this helps and if you have any more questions.

Thanks,
Dan

Hi @dan.woda,

Thank you for getting back to me! This was very helpful and am happy to say I’ve got the right information coming back now with no errors.

I didn’t realize that Management and Authorization had different access tokens for SPA applications.

Thank you again.

-Rejon

1 Like

Glad you got it fixed!

Cheers,
Dan

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