Skip to content

Instantly share code, notes, and snippets.

@djds4rce
Created August 13, 2013 17:05
Show Gist options
  • Save djds4rce/6223291 to your computer and use it in GitHub Desktop.
Save djds4rce/6223291 to your computer and use it in GitHub Desktop.
A Angular Request Interceptor which modifies the configuration object to add auth token to url params of every http call to api server
//Works for 1.1.x versions. 1.0.x is similar and can be figured out using code comments
myapp.factory('httpRequestInterceptor', function ($cookieStore) {
return {
request: function (config) {
var token = $cookieStore.get("auth");
config.url = URI(config.url).addSearch({'_auth_token':token}).toString();
return config;
}
};
});
myapp.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpRequestInterceptor');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment