Management API get access token returns 401 error

I am trying to get an access token for the Management API in a NuxtJS app in a component mounted method following the Auth0 docs as below, with the relevant client ID and secret auto generated by the docs (obscured here), but get a 401 error ‘not authorised’, can anybody help as to where I may be going wrong?

mounted() {

const getToken = {
method: ‘POST’,
url: ‘https://XXXXXXXXXXX.auth0.com/oauth/token’,
headers: {
‘content-type’: ‘application/x-www-form-urlencoded’
},
form: {
grant_type: ‘client_credentials’,
client_id: ‘XXXXXXXXXXXXXXXXXXX’,
client_secret: ‘XXXXXXXXXXXXXXXXXXXX’,
audience: ‘XXXXXXXXXXX.auth0.com/api/v2/
}
};

        this.$axios(getToken).then((res) => {
            console.log(res)
        }).catch(function (error) {
            console.log(error);
        });

}

1 Like

Hi @jamie.warnock,

Welcome to the Community!

You shouldn’t be passing secrets to your client side apps. In this case, you will want to proxy the request through a backend API.

Hope this helps!
Dan

1 Like

Hi Dan,

Thank you for your direction, it does help! does Auth0 have any tutorials on setting up a backend API, for instance a nodeJS express app? I will take a look of course, thanks again.

Regards,
Jamie

1 Like

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