Skip to content
Advertisement

Store bearerToken until expires

I have an application that consumes a REST service from another server, which has its own authentication method to be able to consume its services.

Today, for each request we have, I am calling the authentication service then i receivethe bearerToken (which has a duration of 3 hours) and after that I call the endpoint I want to use.

The flow works without problems but I would like to know if there is a way to store this token in the same application and thus request the renewal of this only when it has expired, avoiding to call the authentication in each request.

Advertisement

Answer

Finally I used the Caffeine Cache library to store the token. Here is the tutorial I followed in case anyone needs it

https://www.baeldung.com/spring-boot-caffeine-cache

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement