# Generating Access Token

**URL:** <https://community.auth0.com/t/generating-access-token/90641>\
**Category:** Get Help\
**Tags:** jwt, api, auth0\
**Created:** [September 14, 2022, 10:47pm UTC](https://community.auth0.com/t/generating-access-token/90641 "2022-09-14T22:47:54Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![argmichael](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/argmichael/32/39948_2.png) [@argmichael](https://community.auth0.com/u/argmichael)\
**Post date:** [September 15, 2022, 9:09pm UTC](https://community.auth0.com/t/generating-access-token/90641/4 "2022-09-15T21:09:36Z")

</div>

EDIT:  
Was able to give consent to the API by calling `getAccessTokenWithPopup`. However still facing issues accessing private and private-scoped endpoints. They are still returning 401 Error.

ORIGINAL:  
Found this post [https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926). Even though I have assigned my user the permissions, I still get the following error in my browser console.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/2/3/23f76d3ff10b52ef3eba9c56849a989f69a9722a.png)

```auto
useEffect(() => {
    const getUserMetadata = async () => {
      try {
        const accessToken = await getAccessTokenSilently({
          audience: "https://webapp/api",
          scope: "read:messages",
        });

        console.log(accessToken);
      } catch (e) {
        console.log("error ", e);
      }
    };

    getUserMetadata();
  }, [getAccessTokenSilently]);

```

```auto
Error: Consent required
    at new OAuthError (errors.tsx:8:1)
    at utils.tsx:15:1
    at auth0-provider.tsx:326:1
    at step (vendors~main.chunk.js:214:17)
    at Object.throw (vendors~main.chunk.js:145:14)
    at rejected (vendors~main.chunk.js:107:32)

```

---

_[View the full topic](https://community.auth0.com/t/generating-access-token/90641)._
