Skip to content

Support additional authorization schemes #5845

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

Merged
merged 2 commits into from
Nov 4, 2021
Merged
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
15 changes: 14 additions & 1 deletion libraries/HTTPClient/src/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,17 @@ void HTTPClient::setAuthorization(const char * auth)
}
}

/**
* set the Authorization type for the http request
* @param authType const char *
*/
void HTTPClient::setAuthorizationType(const char * authType)
{
if(authType) {
_authorizationType = authType;
}
}

/**
* set the timeout (ms) for establishing a connection to the server
* @param connectTimeout int32_t
Expand Down Expand Up @@ -1178,7 +1189,9 @@ bool HTTPClient::sendHeader(const char * type)

if(_base64Authorization.length()) {
_base64Authorization.replace("\n", "");
header += F("Authorization: Basic ");
header += F("Authorization: ");
header += _authorizationType;
header += " ";
header += _base64Authorization;
header += "\r\n";
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/HTTPClient/src/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class HTTPClient
void setUserAgent(const String& userAgent);
void setAuthorization(const char * user, const char * password);
void setAuthorization(const char * auth);
void setAuthorizationType(const char * authType);
void setConnectTimeout(int32_t connectTimeout);
void setTimeout(uint16_t timeout);

Expand Down Expand Up @@ -251,6 +252,7 @@ class HTTPClient
String _headers;
String _userAgent = "ESP32HTTPClient";
String _base64Authorization;
String _authorizationType = "Basic";

/// Response handling
RequestArgument* _currentHeaders = nullptr;
Expand Down