# Calling API in a SPA

**URL:** <https://community.auth0.com/t/calling-api-in-a-spa/6123>\
**Category:** Get Help\
**Tags:** spa, api, management-api, lock\
**Created:** [April 6, 2017, 2:37am UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123 "2017-04-06T02:37:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandao](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@brandao](https://community.auth0.com/u/brandao)\
**Post date:** [April 6, 2017, 2:37am UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123/1 "2017-04-06T02:37:41Z")

</div>

I have a SPA in React and am trying to login with auth0-lock and then make requests to a .NET Web API 2 on Azure registered on auth0.

My lockOptions are:

```

{  
oidcConformant: true,
auth: {  
        responseType: 'id_token token',  
        params: {  
          audience: auth_audience,  
          scope: 'openid'  
        }  
      }  
}

```

I am passing through the consent page and getting an access\_token and id\_token but when I try to make a request using my access\_token, I receive a 401 Unauthorized. The API is working fine when I make a request to a public endpoint.  
I tried to follow [this example](https://github.com/auth0-samples/auth0-react-sample/tree/master/08-Calling-Api), but I am facing [this issue](https://github.com/auth0-samples/auth0-react-sample/issues/45)

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [April 6, 2017, 1:29pm UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123/2 "2017-04-06T13:29:53Z")

</div>

You need to ensure that your API is validating the access\_token correctly.

- If your API is configured for HS256,  
ensure that your API is using the API  
`Signing Secret` to validate the  
token. You can find this in the API  
settings in the Auth0 Dashboard.

- If configured for RS256, you need to  
ensure you are using the public key  
to validate the token - this can be  
obtained from  
`https://your-tenant.auth0.com/.well-known/jwks.json`.

---

<div class="post-metadata">

**Author:** ![brandao](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@brandao](https://community.auth0.com/u/brandao)\
**Post date:** [April 6, 2017, 8:28pm UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123/3 "2017-04-06T20:28:15Z")

</div>

I’ve used this example to implement our WEB API 2:  
[https://github.com/auth0-samples/auth0-aspnet-owin-webapi-sample/tree/master/01-Authentication/WebApi](https://github.com/auth0-samples/auth0-aspnet-owin-webapi-sample/tree/master/01-Authentication/WebApi)  
It only uses Audience and Domain as parameters to configure the authentication, so I’m assuming it is working with RS256?  
When using a Non-Interactive client, everything works as expected, the access\_token is validated properly with the registered API, the same just isn’t true for the react client.

---

<div class="post-metadata">

**Author:** ![brandao](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@brandao](https://community.auth0.com/u/brandao)\
**Post date:** [April 6, 2017, 8:28pm UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123/4 "2017-04-06T20:28:37Z")

</div>

I’ve used this example to implement our WEB API 2: [https://github.com/auth0-samples/auth0-aspnet-owin-webapi-sample/tree/master/01-Authentication/WebApi](https://github.com/auth0-samples/auth0-aspnet-owin-webapi-sample/tree/master/01-Authentication/WebApi) It only uses Audience and Domain as parameters to configure the authentication, so I’m assuming it is working with RS256? When using a Non-Interactive client, everything works as expected, the access\_token is validated properly with the registered API, the same just isn’t true for the react client.

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [April 7, 2017, 12:14pm UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123/5 "2017-04-07T12:14:25Z")

</div>

@brandao You need to ensure that you are requesting the desired scopes for the API, e.g. `read:contacts`. The following document outlines the execution of the implicit grant flow:

> **[Implicit Flow with Form Post](https://auth0.com/docs/get-started/authentication-and-authorization-flow/implicit-flow-with-form-post)**
>
> Learn how the Implicit flow with Form Post works and why you should use it for traditional web apps that need only an ID Token to perform user authentication.

---

<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:** [March 2, 2018, 5:53am UTC](https://community.auth0.com/t/calling-api-in-a-spa/6123/6 "2018-03-02T05:53:06Z")

</div>


