Closed scollinson closed 11 years ago
Sorry, as you may have been able to tell, this is tied to using restangular with angular-http-auth. What is happening is that I am able to set the header for future requests but the replayed request uses the old config and hence the old headers.
See my pull request.
Hi @scollinson, would you mind sharing a gist of how you're doing your token setting wrt restangular headers? I've been struggling with this for a few hours and have something working but I feel I'm going about things the wrong way. Many thanks.
I'm using the following to store my CSRF token: $http.defaults.headers.post['x-csrf-token'] = response['X-Csrf-Token']; Maybe this helps?
Thanks @diego-vieira . What I'm actually asking is how to integrate angular-http-auth with restangular as @scollinson described above to set headers for the deferred requests so that when they're replayed they include the token received via the authentication process.
Hi @bjubinville, As you can see in my accepted pull request (https://github.com/witoldsz/angular-http-auth/pull/36) you can now pass an updater function to the loginConfirmed function. This function returns a modified version of the request config to be retried. Here's an example:
authService.loginConfirmed(undefined, function(config) {
config.headers = _.extend(config.headers, {'Authentication-Token': response.token});
return config;
});
Hope that helps. Let me know if you have any more troubles.
Perfect, thanks much @scollinson (and again thanks @diego-vieira).
I'm using angular-http-auth with an API that uses a token in a header for authentication. I am capturing 401 responses and prompting the user to create a token. Once this token is created I would then like to add it to the headers of any further requests and also the request that has been deferred.
Passing a function to setDefaultHeaders would allow me to use $cookieStore to fetch the token for further requests. Adding the header to the deferred request I have no idea how to do.