Get Authorization Api Token

Hi, I need help with a development to get an authorization token for my user CRUD. I am removing a user first from auth0 and then from my database(with a try catch) but for that I need the authorization token and I am passing it manually because I am having problems to get it with the API.
My current code with the jwt set manually:

export const deleteUser = async (id) => {
    try {

        const auth0Endpoint = `|${id}`;
        const auth0Headers = new Headers();

        auth0Headers.append("Authorization", `Bearer MyAccessTokenHardcoded`);

        const requestOptions = {
            method: 'DELETE',
            headers: auth0Headers,
            redirect: 'follow'

        // Realiza la solicitud de eliminación en Auth0
        const auth0Response = await fetch(auth0Endpoint, requestOptions);

        // Verifica si la eliminación en Auth0 fue exitosa
        if (auth0Response.status === 204) {
            // Si la eliminación en Auth0 fue exitosa, elimina el usuario en tu base de datos
            const response = await interceptor.delete(`/${id}`);
        } else {
            console.log('Error al eliminar usuario en Auth0:', auth0Response.statusText);
    } catch (error) {

This works but it is not efficient to have to keep updating my token.
The token that is working for me is in: Api’s → Auth0 Managment Api → Api explorer

Hey there @auth0-ikearg!

Good to know you’ve got this working manually setting the Management API token, that’s a good start!

You’ll want to take a look at the docs on obtaining Management API Access tokens for production - In particular, I recommend looking at node-Auth0 , the node Management API client.

Hey @tyf!
Thank you for guiding me on this path. I am looking at the links that you just send me. They are very useful.
My problem is that I am not using a backend for auth0. Everything is in my React application and when I want to get the token I get some errors in the request usually status 500. I already activated the cors in my application panel. I don’t know if I need to create a different api to request this token from my application or if I can request the default “Auth0 Management API”.

1 Like

No problem, happy to help where I can!

If you do not have a backend to handle Management API tokens, then you will be limited in terms of which scopes are able to be requested. The reason being that a a front-end application cannot securely store a token, credentials, etc. Please see our documentation on confidential and public applications.

Typically, you would use a backend to proxy requests like delete a user:

You can find an example of what that might look like here.

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