# Elasticsearch-angular js authentication issue

**URL:** <https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34411>\
**Category:** Elasticsearch\
**Created:** [November 12, 2015, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34411 "2015-11-12T12:40:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKumarMN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skumarmn/32/27537_2.png) [@SKumarMN](https://discuss.elastic.co/u/SKumarMN)\
**Post date:** [November 12, 2015, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34411/1 "2015-11-12T12:40:39Z")

</div>

Hi,

I am using elasticsearch-angular.js client to connect to my ES instance which has custom security plugin installed. Below is the code i am using to make connection

myServices.service('es', ['esFactory',  
function (esFactory, $http) {  
return esFactory({  
host: '[http://esadmin:esadmin@localhost:9200](http://esadmin:esadmin@localhost:9200)',  
log: 'trace'  
});  
}]);

I have enabled cors in ES as below  
http.cors:  
enabled: true  
allow-origin: "/.\*/"  
allow-credentials: true  
allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"  
allow-methods: "OPTIONS, HEAD, GET, POST, PUT, DELETE"

However i get the below errors when inspected in chrome

OPTIONS [http://localhost:9200/](http://localhost:9200/)

XMLHttpRequest cannot load [http://localhost:9200/](http://localhost:9200/). Response for preflight has invalid HTTP status code 401

Could you please help me out

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 14, 2015, 6:42pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34411/2 "2015-11-14T18:42:40Z")

</div>

Answered in this thread:

> [@Elasticsearch-angular.js authentication issue](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412):
>
> Hi, I am re-posting this here as there might be lot of UI developers here. I am using elasticsearch-angular.js client to connect to my ES instance which has custom security plugin installed. Below is the code i am using to make connection myServices.service('es', ['esFactory', function (esFactory, $http) { return esFactory({ host: '[http://esadmin:esadmin@localhost:9200](http://esadmin:esadmin@localhost:9200)', log: 'trace' }); }]); I have enabled cors in ES as below http.cors: enabled: true allow-origin: "/.\*/" allow-cre…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:38pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34411/3 "2017-07-05T23:38:29Z")

</div>


