HTTP Authentication
editHTTP Authentication
editIf your Elasticsearch server is protected by HTTP Authentication, you need to provide the credentials to ES-PHP so that requests can be authenticated server-side. There are two ways to enable HTTP Authentication: inline with the host, or via auth
parameters:
Inline Authentication.
$params = array(); $params['hosts'] = array ( 'http://user:pass@localhost:9200', // HTTP Basic Auth ); $client = new Elasticsearch\Client($params);
Only HTTP Basic Auth is supported via the inline syntax. Inline syntax allows different credentials for each host.
Alternatively, you can use the auth
connection parameter:
Auth Connection Parameter.
$params = array(); $params['connectionParams']['auth'] = array( 'user', 'pass', 'Basic' ); $client = new Elasticsearch\Client($params);
The auth
syntax allows all four types of HTTP authentication, although Basic
is the most often used variety. Unlike the inline syntax,
the auth
syntax applies to all connections. This is useful if all servers share the same authentication credentials
After being initialized with authentication credentials, all outgoing requests will automatically include the appropriate HTTP auth headers. Authentication setup is identical regardless of the ConnectionClass you are using (e.g. GuzzleConnection or CurlMultiConnection)