# Elasticsearch-angular.js authentication issue

**URL:** <https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412>\
**Category:** Kibana\
**Created:** [November 12, 2015, 12:43pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412 "2015-11-12T12:43:25Z")\
**Posts on this page:** 4\
**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:43pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412/1 "2015-11-12T12:43:25Z")

</div>

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-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, 3:50pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412/2 "2015-11-14T15:50:15Z")

</div>

The ES plugin you're using doesn't respond properly to the OPTIONS request. See [http://stackoverflow.com/a/15734032/414355](http://stackoverflow.com/a/15734032/414355).

---

<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 15, 2015, 4:15am UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412/3 "2015-11-15T04:15:50Z")

</div>

Thanks @magnusbaeck it helped me to resolve the issue..

---

<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 6, 2017, 2:09pm UTC](https://discuss.elastic.co/t/elasticsearch-angular-js-authentication-issue/34412/4 "2017-07-06T14:09:03Z")

</div>


