Add skipauthorization for object request using Restangular
I am using Satellizer for authentication in my application, by default the Satellizer intercepts the whole request and adds an authorization header. I am making my entire request to my API using Restangular, but I donβt want to send an authorization header in the whole request I make, for example the login and registration endpoints do not need this header. If I add skipauthorization: true to the request object, the Satellizer will not add an authorization header. So my question is, how do I add a skipauthorization property to some of my requests using Restangular.
I tried
Restangular.all('signup').withHttpConfig({'skipAuthorization': true}).post(user)
But "withHttpConfig" is not the function I am looking for.
+3
source to share
1 answer
You need to write a request interceptor:
// set full request interceptor
RestangularProvider.setFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) {
return {
element: element,
params: params,
headers: headers,
httpConfig: _.extend(httpConfig, {skipAuthorization: true})
};
});
0
source to share