Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auth_type param to fix issue 1789 #1790

Merged
merged 6 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ class ClientConfiguration
'transport' => null,
'persistent' => true,
'timeout' => null,
'connections' => [], // host, port, path, transport, compression, persistent, timeout, username, password, config -> (curl, headers, url)
'connections' => [], // host, port, path, transport, compression, persistent, timeout, username, password, auth_type, config -> (curl, headers, url)
'roundRobin' => false,
'retryOnConflict' => 0,
'bigintConversion' => false,
'username' => null,
'password' => null,
'auth_type' => null //basic, digest, gssnegotiate, ntlm
];

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,12 @@ public function getPassword()
{
return $this->hasParam('password') ? $this->getParam('password') : null;
}

/**
* @return string AuthType
*/
public function getAuthType()
{
return $this->hasParam('auth_type') ? strtolower($this->getParam('auth_type')) : null;
}
}
22 changes: 20 additions & 2 deletions src/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Http extends AbstractTransport
* Makes calls to the elasticsearch server.
*
* All calls that are made to the server are done through this function
*
* @param Request $request
* @param array $params Host, Port, ...
*
* @throws ConnectionException
Expand Down Expand Up @@ -104,7 +104,7 @@ public function exec(Request $request, array $params): Response
$username = $connection->getUsername();
$password = $connection->getPassword();
if (null !== $username && null !== $password) {
\curl_setopt($conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\curl_setopt($conn, CURLOPT_HTTPAUTH, $this->_getAuthType());
\curl_setopt($conn, CURLOPT_USERPWD, "{$username}:{$password}");
}

Expand Down Expand Up @@ -222,4 +222,22 @@ protected function _getConnection(bool $persistent = true)

return self::$_curlConnection;
}

protected function _getAuthType()
{
switch ($this->_connection->getAuthType()) {
case "digest":
return CURLAUTH_DIGEST;
break;
case "gssnegotiate":
return CURLAUTH_GSSNEGOTIATE;
break;
case "ntlm":
return CURLAUTH_NTLM;
break;
case "basic":
default:
return CURLAUTH_BASIC;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the default value was CURLAUTH_ANY. I wonder if this change could break some setups?

Copy link
Contributor Author

@daalvand daalvand Jul 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the code and now the _getAuthType function by default returns CURLAUTH_ANY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added changelogs

}
}
}