tjoudeh/AngularJSAuthentication — pull request #2 by Excolo (2014-08-01 23:55:58+00:00)
Title: Added support for auto refresh of tokens.

In the comment section of [Enable OAuth Refresh Tokens in AngularJS... part 3](http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/), there was a wish to enable seamless refresh token requests.

One way of doing this is to intercept the http response error and use the ideas in the [angular-http-auth library](https://github.com/witoldsz/angular-http-auth) to refresh the token and retry the original http request.

This commit does the job. :-)

I've basically replaced the code that relocates to the refresh page in the response error interceptor, with a call to the refreshToken() method in the authService, and if this call is succesful, we retry the intercepted http request.

The $http service is being injected by the $injector service instead of through the service constructor arguments, in order to avoid getting the cyclic dependency error. This is done both in the authInterceptorService and the authService.