3

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.

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

But is it possible to do it with RestAngular?
There is this question here stackoverflow.com/a/18867662/3836923 where the op ended up using a full request interceptor to inject the headers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.