I\'m banging my head on a wall with this - I\'m relatively new to working with APIs and have yet to do anything that requires authentication.
I\'m stuck with sendin
Call this once you have a token:
$httpProvider.defaults.transformRequest.push(function (data, headersGetter) {
if (authToken !== null) {
var headers = headersGetter();
angular.extend(headers, 'Authorization: basic ' + authToken);
}
return data;
});
EDIT: Have not tested it, but it should be something like:
myApp.provider('authService', function() {
var authToken = null;
this.$get = ['$httpProvider', function($httpProvider) {
return {
configure: configure,
setAuthToken: setAuthToken
}
};
function configure() {
$httpProvider.defaults.transformRequest.push(function (data, headersGetter) {
if (authToken !== null) {
var headers = headersGetter();
angular.extend(headers, 'Authorization: basic ' + authToken);
}
return data;
});
}
function setAuthToken(token) {
authToken = token;
}
});
and then inject authService to your app config and call authService.configure()