Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am using restangular to talk to a RESTful api. The API requires a valid token to authenticate against.

Users in the app have logged in and have a generated token. How do I set the default headers/intercept requests after login to include this token header.

I have been able to do it when I first bootstrap the application using RestangularProvider.setFullRequestInterceptor but the user has not logged in at this stage and does I can not therefore insert he header.

share|improve this question
up vote 3 down vote accepted

If you want to add it to the header, look at $http.defaults object\array. Since Restangular also uses $http this would affect Restangular too.

You can inject $http into the service which gets the access token and that service can add to the defaults.

Check $http documentation http://docs.angularjs.org/api/ng.$http

share|improve this answer
4  
But is it possible to do it with RestAngular? – STEVER Mar 4 '14 at 9:23
    
There is this question here stackoverflow.com/a/18867662/3836923 where the op ended up using a full request interceptor to inject the headers. – inkalimeva May 18 at 21:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.