# Authorization fails when trying to fetch /api/v2/users/

**URL:** <https://community.auth0.com/t/authorization-fails-when-trying-to-fetch-api-v2-users/94277>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [November 11, 2022, 4:03pm UTC](https://community.auth0.com/t/authorization-fails-when-trying-to-fetch-api-v2-users/94277 "2022-11-11T16:03:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![altern](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/altern/32/33478_2.png) [@altern](https://community.auth0.com/u/altern)\
**Post date:** [November 11, 2022, 4:03pm UTC](https://community.auth0.com/t/authorization-fails-when-trying-to-fetch-api-v2-users/94277/1 "2022-11-11T16:03:42Z")

</div>

I have the following flow for my single page web app:

```auto
        const access_token = await getAccessTokenSilently({
          audience: 'https://dev- ********.us.auth0.com',
          scope: ['read:users', 'read:user_idp_tokens'],
        }); 
        console.log("Access token: " + access_token)
        const userWithToken = await fetch("https://dev- ********.us.auth0.com/api/v2/users/" + user.sub + "?include_fields=true", {
          headers: {
            Authorization: `Bearer ${access_token}`
          }
        })
        const token = userWithToken.identities[0].access_token 
        console.log("Token:" + token)
        const response = await fetch('https://api.github.com/users/' + user.nickname + '/repos', {
          headers: {
            Accept: `application/vnd.github+json`,
            Authorization: `token ${token}`,
          },
        });
        console.log(response)

```

The problem is that call to `https://dev-********.us.auth0.com/api/v2/users/`always fails. Either with 401 `Bad audience` error (if I specify [https://api.github.com/](https://api.github.com/) as an audience when doing `getAccessTokenSilently`) or `Consent is required` (if I specify `https://dev-********.us.auth0.com/api/v2/` as an audience) or plain 400 (if I call `getAccessTokenSilently` without audience or any params).

How do I make this work?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 14, 2022, 5:32pm UTC](https://community.auth0.com/t/authorization-fails-when-trying-to-fetch-api-v2-users/94277/3 "2022-11-14T17:32:31Z")

</div>

Hi @altern,

I moved this topic to the #Help category (please use this in the future for similar questions.

> [@altern](#):
>
> How do I make this work?

You cannot get the `read:user_idp_tokens` [scope for a token requested from a client-side app](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-tokens-for-single-page-applications).

You must use a backend service to retrieve the IdP token (github token).

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 28, 2022, 5:32pm UTC](https://community.auth0.com/t/authorization-fails-when-trying-to-fetch-api-v2-users/94277/4 "2022-11-28T17:32:46Z")

</div>

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