Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs with restangular inject header after authentication

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.

like image 323
John Royal Avatar asked Feb 15 '26 08:02

John Royal


1 Answers

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

like image 188
Chandermani Avatar answered Feb 18 '26 07:02

Chandermani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!