title: AngularJS token authentication with sliding expiration in state transitions with ui-router version 1.x
body: <p>In our application we have a requirement that user should be logged in for a certain amount of time which is configurable by system admin, say 10 minutes. We have another requirement that the when user navigates to different parts of the app, this time should be refreshed and set back to that configured amount.</p>
  
  <p>Our application is written in <code>AngularJS</code> and we use <code>ui-router</code> for routing, So when user navigates between different states, time to be logged out gets updated.</p>
  
  <p>The back-end is written with .NET and we use jwt tokens for authentication, Token has a field named <code>expiration</code>. In the beginning of each request we check if the token is not expired.</p>
  
  <p>I have a problem that I don't know how to tell the server that it should update the token expiration time, I am using <code>ui-router</code> version 1 and it has some hooks for doing server side things before state transitions, I ended up with something like this:</p>
  
  <pre><code>  $transitions.onBefore({
        to: "*"
    }, function(trans) {      
       // update the client ui, and also tell the server to update
       // the timeout in the serverside and database
  
       return authService.refreshToken();
    });
  </code></pre>
  
  <p>But I am uncertain about this approach being correct, I couldn't find a good solutions for such problem in a REST architecture, I would be very grateful if you could tell me the pros and cons of this method or point me to the right implmentation</p>