rest - Basic HTTP Authentication doesn't work in AngularJS -
my angularjs driven frontend should use basic auth. i've tried different approaches, nothing works -- request sent without authorization
header:
$http
service object config
code
(function() { var app = angular.module('portfolio', []); app.controller('projectslistcontroller', ['$http', function($http) { var projectslist = this; projectslist.projectslistdata = []; $http.defaults.headers.common.authorization = 'basic dxnlcjpwd2q='; $http.get(config['api_server_url'] + '/projects').success(function(data) { projectslist.projectslistdata = data; }); }]); })();
request headers
options /projects http/1.1 host: foo.bar.tld connection: keep-alive access-control-request-method: origin: http://baz.buz.loc user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/41.0.2272.118 safari/537.36 access-control-request-headers: accept, authorization accept: */* referer: http://baz.buz.loc/ accept-encoding: gzip, deflate, sdch accept-language: de-de,de;q=0.8,en-us;q=0.6,en;q=0.4,ru;q=0.2
- request config:
code
(function() { var app = angular.module('portfolio', []); app.controller('projectslistcontroller', ['$http', function($http) { var projectslist = this; projectslist.projectslistdata = []; $http.get(config['api_server_url'] + '/projects', { headers: {'authorization': 'basic dxnlcjpwd2q='} }).success(function(data) { projectslist.projectslistdata = data; }); }]); })();
request headers
options /projects http/1.1 host: foo.bar.tld connection: keep-alive cache-control: max-age=0 access-control-request-method: origin: http://baz.buz.loc user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/41.0.2272.118 safari/537.36 access-control-request-headers: accept, authorization accept: */* referer: http://baz.buz.loc/ accept-encoding: gzip, deflate, sdch accept-language: de-de,de;q=0.8,en-us;q=0.6,en;q=0.4,ru;q=0.2
app
config
code
(function() { var app = angular.module('portfolio', []); app.run(['$http', function($http) { $http.defaults.headers.common['authorization'] = 'basic dxnlcjpwd2q='; }]); app.controller('projectslistcontroller', ['$http', function($http) { var projectslist = this; projectslist.projectslistdata = []; $http.get(config['api_server_url'] + '/projects').success(function(data) { projectslist.projectslistdata = data; }); }]); })();
request headers
accept:*/* accept-encoding:gzip, deflate, sdch accept-language:de-de,de;q=0.8,en-us;q=0.6,en;q=0.4,ru;q=0.2 access-control-request-headers:accept, authorization access-control-request-method:get connection:keep-alive host:foo.bar.tld origin:http://baz.buz.loc referer:http://baz.buz.loc/ user-agent:mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/41.0.2272.118 safari/537.36
so, authorization: basic dxnlcjpwd2q=
header missing. wrong here , how working?
as in this question, need set configuration of $http
service not in controller, in run
or config
block
app.run(['$http', function($http) { $http.defaults.headers.common['authorization'] = /* ... */; }]);