Store bearerToken until expires

Viewed 25

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.

1 Answers

Store both the token and the expiry time in the application. Whenever you need to use the token, check the expiry time. If need be renew the token before using it.

Related