Using the management API in flow actions

My objective is to use the management API in a custom action.

This could be done in rules like this:

const ManagementClient = require('auth0@2.17.0').ManagementClient;
const management = new ManagementClient({
    token: auth0.accessToken,
    domain: auth0.domain,
});

How would something similar look like in a custom action?

UPDATE
Currently get the ManagementClient like this:

   const { MGMT_DOMAIN, MGMT_ID, MGMT_SECRET } = context.secrets;
    const ManagementClient = require('auth0').ManagementClient;
    var management = new ManagementClient({
        domain: MGMT_DOMAIN,
        clientId: MGMT_ID,
        clientSecret: MGMT_SECRET,
    });

I believe your current code is the best way to initialize the Management API client in Actions, but I am double checking with the team!

1 Like

Hi @alexab,

I just received confirmation that your current code is the best way to initialize the Auth0 client. In order to gather more info about Management API use cases in Actions as we build out more functionality, would you mind explaining how you’d like to use the client? Thank you!

Current known use cases for using the management client:

  • user/app metadata updates (already covered in actions)
  • user linking (not covered yet)
  • adding roles/permissions to users (not covered yet)
1 Like

Thanks for a great reply. So in the ideal world, I would like:

  1. The management API was just ready to use without a require statement, or at least could be initialized without any required parameters (it should be able to grab domain, clientId, secrets etc. from the context).
  2. My specific use-case was user linking and user/app metadata updates, but when I look at the documentation for the management API, I can see many potential relevant operations :thinking:

I hope that answers the question. Now that I have your attention, would you mind taking a look at one of my other questions regarding actions here? I know that I can always contact auth0 support and get really good help, I just think it makes more sense for the general public to have these things covered. In my opinion it’s just faster/better to find the answers in the community that opening/closing support cases :upside_down_face:

Thanks for a great reply. So in the ideal world, I would like:

  1. The management API was just ready to use without a require statement, or at least could be initialized without any required parameters (it should be able to grab domain, clientId, secrets etc. from the context).
  2. My specific use-case was user linking and user/app metadata updates, but when I look at the documentation for the management API, I can see many potential relevant operations :thinking:

I hope that answers the question :slight_smile:

Thank you for sharing that feedback! I’ve passed it on to the team.

Yes, thanks for sharing these questions with the Community!

1 Like