# Have a SPA react application and backend api springboot

**URL:** <https://community.auth0.com/t/have-a-spa-react-application-and-backend-api-springboot/111537>\
**Category:** Get Help\
**Tags:** other, missing-category\
**Created:** [July 18, 2023, 5:18pm UTC](https://community.auth0.com/t/have-a-spa-react-application-and-backend-api-springboot/111537 "2023-07-18T17:18:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TalhaRizwan093](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/talharizwan093/32/49005_2.png) [@TalhaRizwan093](https://community.auth0.com/u/TalhaRizwan093)\
**Post date:** [July 18, 2023, 5:18pm UTC](https://community.auth0.com/t/have-a-spa-react-application-and-backend-api-springboot/111537/1 "2023-07-18T17:18:06Z")

</div>

I have a React app application on authO and an API having a permission of read:message.  
Now I had successfully configured the SPA and backend spring boot application. Springboot is configured as backend api app with the audience key from the SPA application. Now i can access the endpoints that does not need any permission but when i hit the endpoint that needs the permission it says 403 forbidden error

frontend code

```auto
const {
    user,
    isAuthenticated,
    loginWithRedirect,
    logout,
    getIdTokenClaims,
    getAccessTokenSilently,
  } = useAuth0();

const getToken = async () => {
    if (isAuthenticated) {
      try {
        // Get the ID token claims, which include the access token
        const idTokenClaims = await getIdTokenClaims();
        const accessToken = idTokenClaims.__raw; // The access token

        console.log(accessToken);
       

        const response = await fetch(
          "http://localhost:3010/api/private-scoped",
          {
            headers: {
              Authorization: `Bearer ${token}`,
            },
          }
        );
        console.log(response);
        const data = await response.json();
        console.log(data);
        // Handle the API response
      } catch (error) {
        console.log(error);
        // Handle errors
      }
    }
  };

```

backend scurity code:

```auto
 @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .mvcMatchers("/api/public").permitAll()
                .mvcMatchers("/api/private").authenticated()
                .mvcMatchers("/api/private-scoped").hasAuthority("SCOPE_read:messages")
                .and().cors()
                .and().oauth2ResourceServer().jwt();
        return http.build();
    }

```

remember the endpoint /api/private is giving 200 so no configuration error.

---

<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:** [July 21, 2023, 6:21pm UTC](https://community.auth0.com/t/have-a-spa-react-application-and-backend-api-springboot/111537/3 "2023-07-21T18:21:11Z")

</div>

Hi @TalhaRizwan093,

Welcome to the Auth0 Community!

This line could be the problem:

```js
const accessToken = idTokenClaims.__raw;

```

The Access token and ID token are different. This quickstart shows how to get the access token and use it to call your API: [Auth0 React SDK Quickstarts: Call an API](https://auth0.com/docs/quickstart/spa/react/02-calling-an-api)

---

<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:** [August 4, 2023, 6:22pm UTC](https://community.auth0.com/t/have-a-spa-react-application-and-backend-api-springboot/111537/4 "2023-08-04T18:22:02Z")

</div>

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