# How to get authenticated directly in Spring Boot API with oAuth 2 with PKCE

**URL:** <https://devforum.okta.com/t/how-to-get-authenticated-directly-in-spring-boot-api-with-oauth-2-with-pkce/15166>\
**Category:** Questions\
**Created:** [July 19, 2021, 9:06am UTC](https://devforum.okta.com/t/how-to-get-authenticated-directly-in-spring-boot-api-with-oauth-2-with-pkce/15166 "2021-07-19T09:06:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karinea](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@karinea](https://devforum.okta.com/u/karinea)\
**Post date:** [July 19, 2021, 9:06am UTC](https://devforum.okta.com/t/how-to-get-authenticated-directly-in-spring-boot-api-with-oauth-2-with-pkce/15166/1 "2021-07-19T09:06:27Z")

</div>

Hello,  
We have a React Web App independent from our Spring Boot Api app. We configured our Spring Boot App as a ressource server. And we have succeeded to authenticate to OKTA using oAuth 2 PKCE authorization flow from React SPA.

If we try to access the same endpoints from our Spring Boot App, which by the way has a Swagger inside it, we are not authorized. For example, if we try to access to **localhost:3000/getData** passing by React SPA we get authenticated by OKTA and get the authorization to access the data from Spring boot API ressource server. But, if we try to access to **localhost:8080/getData** we get rejected.

- How can we still be able to access the same endpoints in Spring Boot API (Swagger) ?
- How can we authenticate with OKTA directly on the backend to our ressource server, but still keeping the ability to connect via React SPA ?

Many thanks for your help

---

<div class="post-metadata">

**Author:** ![karinea](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@karinea](https://devforum.okta.com/u/karinea)\
**Post date:** [July 28, 2021, 12:11pm UTC](https://devforum.okta.com/t/how-to-get-authenticated-directly-in-spring-boot-api-with-oauth-2-with-pkce/15166/2 "2021-07-28T12:11:13Z")

</div>

Here’s the solution we have found along with the stackoverflow members [okta - Use several spring security configuration and apply them according to the calling url - Stack Overflow](https://stackoverflow.com/questions/68496436/use-several-spring-security-configuration-and-apply-them-according-to-the-callin)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [July 29, 2021, 12:11pm UTC](https://devforum.okta.com/t/how-to-get-authenticated-directly-in-spring-boot-api-with-oauth-2-with-pkce/15166/3 "2021-07-29T12:11:44Z")

</div>

Closed on July 29, 2021, 12:11pm UTC

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