Spring-Boot and React Integration
-
Hi guys,
after reading here through this forum and trying almost every example here. I stuck to provide the react App with the JWT token from FusionAuth from my Spring-Boot Application.
I integrated this: https://fusionauth.io/blog/2018/10/24/easy-integration-of-fusionauth-and-spring/
and it works, but I get the JSSESSIONID in the Cookie instead of JWT Token provided from FusionAuth.
Basically I want my React application redirect to my Spring Boot Server, the spring boot redirects to the FusionAuth exchanges the code for token, reads the user AND (This part ist not working!!!) should give the JWT and User to the React app.
The React App would user the JWT Token to communicate to the spring-boot backend and the spring boot would validate the token against the fusionAuth issuer-uri.
Do you have any similar running example? It's quite frustrating.
I could find an React -> NodeJS (Experss) -> FusionAuth Example, but could not find anything similar for spring boot. The example Above is an example for Spring-Boot Server Side rendered Application: Frontened and Backend on Spring-Boot server.
Any Examples, that would help a lot? Even if its Angular/Vue or whatever to Spring-Boot, will be fine as well.
-
From your earlier ticket, were you able to get this working, or would you like some additional thoughts?
Thanks,
Josh -
@alexander-schamne I think that you're messing the things a bit. I don't know Spring boot so I might be wrong but in general, it seems to me that you have a typical setup with FusionAuth, backend (Spring boot server) and SPA frontend (react).
There are multiple workflows for such setup described in the docs: https://fusionauth.io/learn/expert-advice/authentication/login-authentication-workflows/
In your case this one: https://fusionauth.io/learn/expert-advice/authentication/spa/oauth-authorization-code-grant-sessions/ might be the best choice as it seems it is what you've implemented already.
What seems to be wrong with your current solution is that you're expecting JWT token to be automatically passed to the REACT. Unless there is some magic that Spring libraries do, that will not happen. At least I can't see anything about this in the Spring/FA integration example you've linked. This example seems to be about regular Spring application that is using sessions. Because of that it should be OK that you get JSESSIONID in the cookie.
By having this cookie (and session) you have your user logged in so it should be enough for your REACT application to be able to connect to the server and have user identified (exactly as described in the workflow I've linked above). -
Hi Maciej, I dont thing that I am messing up something.
Finally I got it up and running by just "try and error". With an old FusionAuth documentation and examples
React App: gets the token from FusionAuth and communicates with this token to the Spring Boot Backend
Spring Boot Backend: Checks the token using FusionAuth as JWS Issuer and rejects or accepts as authorised