What is the best practice for authorization and user authentication in REST spring boot?
I am creating a web application with standard pages + REST API for mobile devices. I went through a lot of spring security articles, and most of them come with some kind of suitable method that will allow or block REST calls. In my case, however, I have some auth logic based on who the user is. For example, there is an API /update that updates information about a user, and the user can update himself, but cannot update another person. Initially, I thought of using the following authentication scheme:
- User calls auth API and passes username / password or cookie
- The system generates a short token, saves a database in it.
- The user receives this token, updates his cookie (so JS in the web application can read and use it).
- When a REST call is made, cookies are sent. In the controller, the token is retrieved, checked for expiration, the query is executed in the database to check the token and obtain the user ID.
- Based on the user ID, REST will be allowed or blocked.
Is this the right implementation approach? I have a pretty big mess in my head after reading spring security articles. At least: session auth will not work for me (REST - stateless). I want to make auth for a mobile device without saving my username / password there.
Does it make sense to transfer this token in the REST body itself? What is the case of the GET method?
Thank you very much for sharing your knowledge.
source share