I'm trying to write a $http interceptor which will attach a header in order to authorize the application with a token.
I have an auth service which requests and stores the token for future use.
In the application config, I'm configuring $httpProvider and pushing a new interceptor onto the array.
The interceptor depends on my Auth service, in order to get hold of the token to send each time. In turn, the Auth service depends on $http in order to send the initial request to authenticate and retrieve the auth token.
I end up with a circular dependency graph that looks something like:
$httpProvider ^ \ / v $http <- Auth Service Auth depends on $http, and through $httpProvider, $http depends on Auth.
Is there an elegant way to get around this? I thought about using an intermediate service, but ultimately, that would just be extending the dependency graph. Something needs to be fundamentally changed.
Is it possible to do something like resolve and reconfigure $http after the auth token has been retrieved?