I am getting a 403 response after Api request

I am trying to retrieve users from API using Axios to localhost/3000 like this

...
const accessToken = await getAccessTokenSilently({
      audience: `https://${domain}/api/v2/`,
      scope: "read:users",
 });

...

const options = {
      method: "GET",
      url: `${api}/users`,
        params: {
          q: '',
          search_engine: 'v3',
       },
      headers: {
        Authorization: `Bearer ${accessToken}`,
        'Content-Type': 'application/json',
      },
    };

...
return axios(options)
    .then((response) => response.data)
    .catch((error) => {
      console.error(error);
    });
...

I got the token successfully but always getting an error message:

Error: Request failed with status code 403

I know it is an access token issue, but I don’t know how to fix it, Please Help!

Hi @othmanenaamani,

Welcome to the Auth0 Community!

You cannot get a token with the read:users scope for the management API in a SPA. You need to make this request from a secure server like a backend API.

2 Likes

Oh yeah! that wasn’t permitted.

1 Like

Let us know if you have any other questions!

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