I'm trying to implement token authentication for a REST service based on Spring MVC.
I'm followiong this SO answer: https://stackoverflow.com/a/10864088/1061499 as guideline, but now I need to understand some server-side detail.
When an user is successfully authenticated (first time via username + password) I return a token that stores some information. When the same user sent his token in a request header, I need to identify the associated user and define if is "session" is still alive.
So the way are basically two:
- encrypt the token with an algorithm (which one?) I can also use to decrypt on server side and extract user information
- store token-user association info in application DB also storing session info.
Most suggest the first solution, without storing any info about authentication in DB, but this solution seems to me less secure.
Any suggestion?