Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one specify trusted servers to send XSFR tokens to in Angular $http?

Tags:

angularjs

I need a clean way to specify header data like XSFR tokens and authorization stuff in $http.

Something like this:

$http.defaults.headers.common["Auth_token"] = token;

But then all requests, also to other domains are populated with this header. Then, this fix came, that made sure only same domain received this header. https://github.com/angular/angular.js/issues/1096

Now I'm left with the problem that my server is on another domain (api.example.com), and only this, or other whitelisted servers should get specific headers.

I would love to be able to specify domains for which some headers are targeted for.

$http.defaults.headers.['api.trusted.com']['Auth_token'] = token;

Or similar. Have anyone else solved a similar problem?

like image 209
Kenneth Lynne Avatar asked Jan 17 '26 21:01

Kenneth Lynne


1 Answers

In the latest version of AngularJS you could use freshly-introduced request interceptors to achieve desired results.

like image 61
pkozlowski.opensource Avatar answered Jan 20 '26 20:01

pkozlowski.opensource



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!