# Springboot + React +Okta

**URL:** <https://devforum.okta.com/t/springboot-react-okta/14773>\
**Category:** Questions\
**Created:** [June 17, 2021, 10:36am UTC](https://devforum.okta.com/t/springboot-react-okta/14773 "2021-06-17T10:36:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagarjuna0901](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nagarjuna0901](https://devforum.okta.com/u/nagarjuna0901)\
**Post date:** [June 17, 2021, 10:36am UTC](https://devforum.okta.com/t/springboot-react-okta/14773/1 "2021-06-17T10:36:20Z")

</div>

I’m planning to build an application using react, springboot with Okta as IAM. I don’t want to give access token to UI (react) , Planning to have tokens at spring boot server or dB level.

So, the flow should be like, React redirecting to Okta sign in page , and okta sending auth code and Id token & access token to Spring.

Is it possible ?

If Yes, how UI will come to know whether user got authenticated or not ?  
What values will go to UI to tell application that ‘xyz’ user got authenticated ?

---

<div class="post-metadata">

**Author:** ![nagarjuna0901](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nagarjuna0901](https://devforum.okta.com/u/nagarjuna0901)\
**Post date:** [July 3, 2021, 1:30pm UTC](https://devforum.okta.com/t/springboot-react-okta/14773/2 "2021-07-03T13:30:15Z")

</div>

Some one help me on this ?

---

<div class="post-metadata">

**Author:** ![bdemers](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bdemers/32/23_2.png) [@bdemers](https://devforum.okta.com/u/bdemers)\
**Post date:** [July 6, 2021, 5:18pm UTC](https://devforum.okta.com/t/springboot-react-okta/14773/3 "2021-07-06T17:18:20Z")

</div>

Hey @nagarjuna0901!

Sorry for the delay! What you are describing is typically what we recommend, if a backend can handle authentication, it should.

We have a [React + Kotlin post](https://developer.okta.com/blog/2020/01/13/kotlin-react-crud), the Spring Security configuration bits would be the same for Java too. If you handle the authentication with your backend, then your frontend just uses cookies (you can cluster sessions with Spring Session if you need to).

As for how your UI knows when your user is authenticated or not, that’s and application-specific concern (although a very common one). You could create a REST endpoint that returns info about the currently logged-in user. If your application stores data about the user in a DB, you could perform a query and return the info.

If you just need information about the user you can inject it with the `@AuthenticationPrincipal` annotation:

> <https://github.com/okta-samples/okta-spring-boot-sample/blob/main/src/main/java/com/example/sample/Application.java#L20-L22>

As for what values go to the UI to inform the frontend the user is authenticated, that’s also up to you. Do you need the UI to handle anonymous user requests? If so maybe you create some `/user` endpoint that returns an empty object (or maybe a `403` status code).

You could also look at what JHipster (an application generator) does:  
[Using React](https://www.jhipster.tech/using-react/) (It uses Spring Security by default)

---

<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:** [February 8, 2024, 6:40pm UTC](https://devforum.okta.com/t/springboot-react-okta/14773/4 "2024-02-08T18:40:13Z")

</div>

Closed on February 8, 2024, 6:40pm UTC

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