# How to authorize a SPA to access an API?

**URL:** <https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926>\
**Category:** Get Help\
**Tags:** api, authentication-api, sap\
**Created:** [January 28, 2021, 5:55am UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926 "2021-01-28T05:55:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SageFioLange](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sagefiolange/32/27231_2.png) [@SageFioLange](https://community.auth0.com/u/SageFioLange)\
**Post date:** [January 28, 2021, 5:55am UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926/1 "2021-01-28T05:55:16Z")

</div>

Hi,

I’m using an Auth0 API to authorize an AWS HttpAPI, and it works with the machine-to-machine test application that is auto-generated with every Auth0 API, however I can’t figure out how to get it to work with the Single Page Application that I have setup for the front-end login/logout functionality. What I’d like to happen is:

1: Login to web app via front-end (authenticated within the SPA users) ;  
2: Get an access token from Auth0 API ;  
3: Use access token to call the AWS HttpAPI ;

I’m getting stuck on step 2. Any help is much appreciated!

---

<div class="post-metadata">

**Author:** ![SageFioLange](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sagefiolange/32/27231_2.png) [@SageFioLange](https://community.auth0.com/u/SageFioLange)\
**Post date:** [January 28, 2021, 6:04am UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926/2 "2021-01-28T06:04:05Z")

</div>

const { getAccessTokenSilently } = useAuth0();

```
useEffect(() => {
    (async () => {
        try {
            const token = await getAccessTokenSilently({
                audience: 'https://<AUTH0_API_AUDIENCE>',
                scope: 'read:items'
            });
            const response = await fetch('<AMAZON_API_ENDPOINT>', {
                headers: {
                    Authorization: `Bearer ${token}`
                }
            });
            console.log(await response.json());
        } catch (e) {
            console.error(e)
        }
    })();
}, [getAccessTokenSilently])

```

^^^^ Here is the code that the flow is getting stuck at (copied from [GitHub - auth0/auth0-react: Auth0 SDK for React Single Page Applications (SPA)](https://github.com/auth0/auth0-react) at Getting Started \> Call an API)

---

<div class="post-metadata">

**Author:** ![SageFioLange](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sagefiolange/32/27231_2.png) [@SageFioLange](https://community.auth0.com/u/SageFioLange)\
**Post date:** [January 28, 2021, 6:05am UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926/3 "2021-01-28T06:05:32Z")

</div>

Error: Consent required  
at new OAuthError (auth0-react.esm.js?ae4e:142)  
at eval (auth0-react.esm.js?ae4e:160)  
at eval (auth0-react.esm.js?ae4e:311)  
at step (auth0-react.esm.js?ae4e:87)  
at Object.eval [as throw] (auth0-react.esm.js?ae4e:68)  
at rejected (auth0-react.esm.js?ae4e:59)

^^^^ Here is the error I receive in my browser console (sorry that these are coming as replies, I wish there was a way to edit posts/comments here 😕 )

---

<div class="post-metadata">

**Author:** ![SageFioLange](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sagefiolange/32/27231_2.png) [@SageFioLange](https://community.auth0.com/u/SageFioLange)\
**Post date:** [January 28, 2021, 7:29pm UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926/4 "2021-01-28T19:29:35Z")

</div>

Figured it out by using Permissions tab and assigning permission to User. Feel like a ■■■■■■■ but hopefully this helps someone else.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 29, 2021, 9:28am UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926/5 "2021-01-29T09:28:32Z")

</div>

Perfect! Glad you have figured it out and thanks for sharing with the rest of community!

---

<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:** [February 13, 2021, 9:28am UTC](https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926/6 "2021-02-13T09:28:51Z")

</div>

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