I am developing a simple todo application with Spring Boot. I am using JWT for authorisation. All todos belongs to a user will be get with following endpoint.
@GetMapping("")
public List<Todo> todos(){
//get username from token
//return todos belongs to user
}
I have two problems in here:
- Is getting username from token a good practise?
- What is the best way accessing username with token from a controller class or a service class?
This answer shows how to reach token from controller class. but what if we want to reach token from service class? This answer shows it. But the class is deprecated.