I have a microservice architecture, both of them securized by spring security an JWT tokens.
So, when I call my first microservice, I want to take the JWT token and send a request to another service using those credentials.
How can I retrieve the token and sent again to the other service?
Basically your token should be located in the header of the request, like for example: Authorization: Bearer . For getting it you can retrieve any header value by @RequestHeader() in your controller:
Now you can place the token within the header for the following request:
Now you can pass the HttpEntity to your rest template:
Hope I could help
I've accomplished the task, creating a custom Filter
Then, setting in my config
With that in mind, I've create another class with a ThreadLocal variable to pass the JWT token from the Controller to the Rest Templace interceptor
}
Add interceptor to the config