I have a REST API server with Java Spring that connects to a PostgreSQL database and a Spring Java web server that serves content from the REST API to the client using JavaScript (now browsers, but in the future also mobile applications).
I read a number of articles on how to protect the REST API, but so far I have not been able to make a final decision. I donโt want to have basic authorization, because it doesnโt make sense, since I will need to store credentials in JavaScript, which can be easily accessed and read by someone by accessing the web page and the developer console. I would not want to show any credentials to the end user, so I cannot store them on the client side.
I read a lot about JWT and almost decided to implement it, but I heard that it has some flaws, and since then it has not been so sure if it were the option that I would like to choose. I know that there is oAuth 1.0 or oAuth 2.0, but I donโt know if I want to have something so complicated. I would also like to store hashed user credentials in my own database so that it does not depend on any other credential providers such as social media or Google.
Now I am creating another layer on my web server as a proxy, hoping that it will allow me to authenticate the user at this proxy level with Spring Security and have some kind of cookie or cookies or something to authenticate, but I Iโm not so sure that he will follow this path and increase the response time, add complexity and require me to write controller methods for these endpoints. Now my architecture has the following meanings:
Client (browser) โ Web server โ REST API server โ db
I also refused all external connections and allowed access only to localhost for the REST API at the tomcat level, so I would have to implement the security level only on the web server, which would provide free transit of information between the web server and the REST API, since it is in anyway unavailable.
The web server and REST API are on the same server as the Tomcat instances.
I'm also not sure if this architecture will allow me to authenticate mobile application clients through a web server.
I would be very grateful for any advice that you would have for me in this matter. I'm not so experienced in security, so I lost a bit of what I have to do. Does this architecture make any sense or should I just request the REST API directly from any type of client, be it a web page or a mobile application from different IP addresses and only a secure Rest API? And if I want to protect some subpages of my web page or parts of a mobile application, should it be a completely different level?
Thank you for your help.