title: Should access tokens be refreshed automatically or manually?
body: <p>In the last few days I've been reading on Authentication with refresh and access tokens, but this is one thing I can't find the answer to. Let's say an expired access token is sent. Should the backend automatically refresh it (if a refresh token was provided), or the refreshing should only be done at a refresh endpoint?</p>
  <p>As an example, consider the two following auth flows:</p>
  <h3>Automatically Refreshing</h3>
  <ol start="0">
  <li>User authenticates with username and password. The API sends back a short lived access token containing his data, and a long lived refresh token.</li>
  <li>For every request that requires authentication/authorization, the user will send both tokens on the request headers.</li>
  <li>If the access token is expired, the API will check if a valid refresh token was sent, if it is active and if it belongs to the same user as the access token. If everything looks good then it will sign a new access token and update the response headers with it.</li>
  </ol>
  <p>Front-end doesn't have to worry about refreshing the token, but it still has to look up response headers after each request to check if a new token was sent.</p>
  <h3>Manually Refreshing</h3>
  <ol start="0">
  <li>User authenticates with username and password. The API sends back a short lived access token containing his data, and a long lived refresh token.</li>
  <li>For every request that requires authentication/authorization, the user will send his access token.</li>
  <li>When the access token expires, the user will send his refresh token to the <code>refresh/</code> route. The API checks if the token is valid. If everything looks good, it returns a new access token.</li>
  </ol>
  <p>After every request, the client has to check if the token expired, and if it did it will have to perform a new request to refresh the token. More requests are being made to the server, but on the other hand responsibilities are better separated, since auth route is only responsible for handling access tokens, while the refresh token handling lives in another route.</p>
  <p>I've had some hard time finding resources on the subject, so I'm not quite about sure which solution is better, or even if the solutions I described are correct at all. If I had to pick one, I would go with Automatically Refreshing, since less requests are made, and the client side usability looks better, but as I said, I'm not 100% on this, and thus I'm making that thread.</p>
  <p>How should access tokens be refreshed?</p>