Auth0 Home Blog Docs

How to use the impersonation API?



I’m quite confused with how to use the impersonation API.

In the documentation there are a lot of references to clients and access tokens and different ways of obtaining them. I need to add the audience parameter to the request and for that reason I can’t use user impersonation through the dashboard.

I tried setting the default audience on my tenant configuration - but that didn’t make any difference.

I tried following the guide for using the Impersonation API. It says in the guide to get an access token for the Management API V1. However, the Management API V1 /oauth/token endpoint is deprecated. So fetched an access token for my Management API from the dashboard instead, then tried to use that token for authorizing my request to the Impersonation API, however I’m just getting “Unauthorized” in the response.

I set up a small script for this, using auth0 NodeJS SDK. Here is the code:

var request = require("request")
var AuthenticationClient = require("auth0").AuthenticationClient;

const auth0 = new AuthenticationClient({
  domain: "<domain>",
  clientId: "<global client id>",
  clientSecret: "<global client secret>"

return auth0.clientCredentialsGrant({
  audience: "https://<domain>",
}).then((response) => {
  const access_token = response.access_token;

  auth0.users.impersonate("<user that i want to impersonate>", {
    token: access_token,
    protocol: "oauth2",
    impersonator_id: "<my user id>",
    client_id: "<client id of the client i want to use the token with>",
    additionalParameters: {
      state: "xyz123",
      audience: "<audience>"
  }, function (err, link) {
}).catch((err) => {

Please help!