| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | [[http-clients]]=== HTTP/REST clients and securityThe {es} {security-features} work with standard HTTP{wikipedia}/Basic_access_authentication[basic authentication]headers to authenticate users. Since Elasticsearch is stateless, this header mustbe sent with every request:[source,shell]--------------------------------------------------Authorization: Basic <TOKEN> <1>--------------------------------------------------<1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`Alternatively, you can use<<token-authentication-services,token-based authentication services>>.[discrete][[http-clients-examples]]==== Client examplesThis example uses `curl` without basic auth to create an index:[source,shell]-------------------------------------------------------------------------------curl -XPUT 'localhost:9200/idx'-------------------------------------------------------------------------------[source,js]-------------------------------------------------------------------------------{  "error":  "AuthenticationException[Missing authentication token]",  "status": 401}-------------------------------------------------------------------------------Since no user is associated with the request above, an authentication error isreturned. Now we'll use `curl` with basic auth to create an index as the`rdeniro` user:[source,shell]---------------------------------------------------------curl --user rdeniro:taxidriver -XPUT 'localhost:9200/idx'---------------------------------------------------------[source,js]---------------------------------------------------------{  "acknowledged": true}---------------------------------------------------------[discrete][[http-clients-secondary-authorization]]==== Secondary authorizationSome APIs support secondary authorization headers for situations where you wanttasks to run with a different set of credentials. For example, you can send thefollowing header in addition to the basic authentication header:[source,shell]--------------------------------------------------es-secondary-authorization: Basic <TOKEN> <1>--------------------------------------------------<1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`The `es-secondary-authorization` header has the same syntax as the`Authorization` header. It therefore also supports the use of<<token-authentication-services,token-based authentication services>>. Forexample:[source,shell]--------------------------------------------------es-secondary-authorization: ApiKey <TOKEN> <1>--------------------------------------------------<1> The `<TOKEN>` is computed as `base64(API key ID:API key)`[discrete][[http-clients-libraries]]==== Client libraries over HTTPFor more information about using {security-features} with the languagespecific clients, refer to:* {java-api-client}/_basic_authentication.html[Java]* {jsclient-current}/auth-reference.html[JavaScript]* {es-dotnet-client}/configuration.html[.NET]* https://metacpan.org/pod/Search::Elasticsearch::Cxn::HTTPTiny#CONFIGURATION[Perl]* {es-php-client}/connecting.html[PHP]* https://elasticsearch-py.readthedocs.io/en/master/#ssl-and-authentication[Python]* https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#authentication[Ruby]
 |