title: Best practices for managing auth token
body: <p>I am writing a REST client in Java using the HttpCLient , the REST API that I access needs an auth token for every REST action. This token is valid for 24 hours.</p>
  
  <p>The way I am handling this now is calling a "<code>getAuth()</code>" method everytime I need to make a REST call which seems like an overhead on the auth server. </p>
  
  <p>How can I conveniently store this auth token and manage its life cycle?
  Are there any documented best practices?</p>
  
  <p>I thought of the following solution</p>
  
  <pre><code>public class MySession {
      String user;
      String pass;
      public MySession(String user, String pass) {
          this.user = user;
          this.pass = pass;
      }
  
      public getAuth() {
          //user user, pass to get auth token 
      }
  }
  </code></pre>
  
  <p>and then pass the sessions object to any class that nees the token. If the token is expired, just call this method again</p>