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>.auth0.com",
  clientId: "<global client id>",
  clientSecret: "<global client secret>"
});

return auth0.clientCredentialsGrant({
  audience: "https://<domain>.auth0.com/api/v2/",
}).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) {
    console.log(err);
    console.log(link);
  });
}).catch((err) => {
  console.log(JSON.stringify(err))
})

Please help!

1 Like

As it has been more than a few months since this topic was opened, and there has been no reply or further information provided as to the existence of the issue, we are closing this topic. Please don’t hesitate to create a new topic if this issue is still present, we would be happy to work with you to help find a resolution.