I’ve read several posts and read the documentation and I didn’t understand what the await getManagementApiToken(event, api) function would be; which is in the documentation.
There’s no explanation for anything. There are variables without any type of comment… Could someone explain it to me?
Hi @rhuan.carvalho,
The getManagementApiToken(event, api)
is a function used to generate an access token to be used against the Management API.
The following piece of code should initialize an instance of the Management API:
// Get Management API Token
const token = await getManagementApiToken(event, API);
// Set the domain from Secrets
const domain = event.secrets.TENANT_DOMAIN;
// Initialize a new Management Client instance
const management = new ManagementClient({ domain, token });
Thanks,
Rueben
Hello, thanks for the response. This function in undefined in the code
Cannot find name 'getManagementApiToken'.(2304)
Hi @rhuan.carvalho,
Thanks for the reply.
I have reviewed the code snippet again and found that the correct method to get an access token is management.getAccessToken()
.
With that, I have shared a working code snippet below on initializing an instance of the Management API.
exports.onExecutePostLogin = async (event, api) => {
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.client_id,
clientSecret: event.secrets.client_secret,
});
const token = await management.getAccessToken();
}
From here, you can proceed with the rest of the account linking logic.
I also recommend checking out this knowledge solution as a reference.
Thanks,
Rueben
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.