Created
August 13, 2013 17:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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