NextJs app - getting

Hey, I have a nextjs app configured as “regular web app” in the dashboard. I’m trying to use the management API sdk in the backend before the user login. I’m passing organization name as a parameter and trying to use the …organizations.getByName, so the user doesn’t have to go through the “enter your organization” page. The problem is that I’m not able to use the management API with my nextjs app credentials. It’s weird because is authorized and it appears as a machine to machine. I’m trying to avoid using a different set of credentials since it make sense for a nextjs app to work as m2m.

I’m using this:

var ManagementClient = require('auth0').ManagementClient;
var auth0 = new ManagementClient({
  domain: '{YOUR_ACCOUNT}.auth0.com',
  clientId: '{YOUR_NON_INTERACTIVE_CLIENT_ID}', 
  clientSecret: '{YOUR_NON_INTERACTIVE_CLIENT_SECRET}',
  scope: "read:users write:users read:organizations",
  audience: 'https://{YOUR_TENANT_NAME}.auth0.com/api/v2/',
  tokenProvider: {
   enableCache: true,
   cacheTTLInSeconds: 10
 }
});

And I’m getting :‘{“error”:“access_denied”,“error_description”:“Unauthorized”}’,

Also, I can’t add client credentials as grant type for this app. Any help?

Thanks!
Germán

Hi @german,

Welcome to the Auth0 Community!

I understand that you would like to use the Management API in your backend but encountered the “Unauthorized” error.

After my investigation, it appears that your NextJSApp is a Regular Web Application.

In this case, you will need to use the credentials of a Machine-to-Machine application with the Client Credentials grant enabled to use the Management API.

I recommend checking out Get Management API Access Tokens for Production documentation for more details.

Please let me know how this goes for you.

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.