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

Support NTLM authentication #184

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ RestClient::Connection* conn = new RestClient::Connection("http://url.com");
// configure basic auth
conn->SetBasicAuth("WarMachine68", "WARMACHINEROX");

// to authenticate using the NTLM protocol
conn->SetAuthProtocol( CURLAUTH_NTLM );

// set connection timeout to 5s
conn->SetTimeout(5);

Expand Down
4 changes: 4 additions & 0 deletions include/restclient-cpp/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class Connection {
void SetBasicAuth(const std::string& username,
const std::string& password);

// Allow other authentication protocols to be used (such as NTLM)
void SetAuthProtocol( unsigned int proto ) { authProtocol = proto; }

// set connection timeout to seconds
void SetTimeout(int seconds);

Expand Down Expand Up @@ -254,6 +257,7 @@ class Connection {
std::string username;
std::string password;
} basicAuth;
unsigned long authProtocol = 0;
std::string customUserAgent;
std::string caInfoFilePath;
RequestInfo lastRequest;
Expand Down
3 changes: 2 additions & 1 deletion source/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ RestClient::Connection::performCurlRequest(const std::string& uri,
if (this->basicAuth.username.length() > 0) {
std::string authString = std::string(this->basicAuth.username + ":" +
this->basicAuth.password);
curl_easy_setopt(getCurlHandle(), CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(getCurlHandle(), CURLOPT_HTTPAUTH,
this->authProtocol == 0 ? CURLAUTH_BASIC : this->authProtocol);
curl_easy_setopt(getCurlHandle(), CURLOPT_USERPWD, authString.c_str());
}
/** set error buffer */
Expand Down