I have a client app using jax-rs Client and making REST calls to bunch of services. One of those services uses bearer token authorization, and after first hard authentication (BASIC) lends a json with an access token, expiry delay, token type etc...
{ "access_token": "hashed_value", "token_type": "bearer", "expires_in": 1800 }
I wish to know what would be the best practices for managing this token for replay. Would it be via a global structure like a Map in memory that I would access at each request and update when token comes to expiration ? an other structure ?
To get a new token after expiration, would it be better to manage it requesting a new token based on a 401 status code ? or by requesting it automatically 1 minute or so before the 1800 seconds passes ?