I created a database connection to add new users using the ManagementClient from Auth0.
When I tried using this connection with my “Machine to Machine” application (API Explorer Application), I received the following error:
Connection must be enabled for this client to perform single user creation and signup operations.
I checked the app in my Dashboard and noticed there is no “Connection” tab for “Machine to Machine” applications. So, I clicked on a “Regular Web Application” where I found a “Connection” tab. I enabled my database there and continued using the Client ID and Client Secret of this application with the ManagementClient.
However, I encountered this error:
Client is not authorized to access “https://auth-sp-staging.eu.auth0.com/api/v2/”. You need to create a “client-grant” associated to this API. See: Auth0 Management API v2.
To resolve this, I opened “Applications - APIs” and selected the “Auth0 Management API” (System API). Then, I went to the “Machine to Machine Applications” tab and authorized my regular web application.
After saving, I tried running my code again but now it shows this error:
Invalid token.
Is there something wrong with my code?
import 'dotenv-defaults/config.js';
import {ManagementClient} from 'auth0';
const management = new ManagementClient({
clientId: process.env.AUTH0_CLIENT_ID + '',
clientSecret: process.env.AUTH0_CLIENT_SECRET + '',
domain: process.env.AUTH0_DOMAIN + '',
});
await management.users.create({
email: 'some@email.com',
password: 'this-is-not-empty',
connection: 'Email-Password-Authentication',
});
Best,
Benny