-1

I am facing an issue in my code. I need to pass the generated token in request (K,V) header to valid the user in filter.

Is there any possible ways to set the generate token default in all requests header.

I am using Spring boot, Sql developer. To generate token i am using JWT.

Thanks in advance

sharkrish
  • 11
  • 6
  • It is possible with interceptors. https://www.tutorialspoint.com/spring_boot/spring_boot_interceptor.htm – Seldo97 Aug 16 '20 at 19:47

1 Answers1

0

Try spring filter or interceptors, you can implement a custom filter to ensure all your requests contains auth token in the header

Here is a good tutorial on the filters: https://dzone.com/articles/working-with-filters-in-spring

stark
  • 399
  • 2
  • 13
  • I need to add the token in request header. Can you please help me to add it using interceptor – sharkrish Aug 16 '20 at 19:04
  • In Postman we can add the header. Same i need to achieve in code. – sharkrish Aug 16 '20 at 19:07
  • I hope you are using the rest template to make a request, here is a similar question which answers your question: https://stackoverflow.com/questions/19238715/how-to-set-an-accept-header-on-spring-resttemplate-request#:~:text=I%20suggest%20using%20one%20of,headers%20%3D%20new%20HttpHeaders()%3B%20headers. – stark Aug 17 '20 at 03:31