Skip to content

Commit 26f51a4

Browse files
committed
Add support for basic authentication
1 parent ef8e748 commit 26f51a4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Release/src/http/client/http_client_asio.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ class asio_context : public request_context, public std::enable_shared_from_this
630630
{
631631
extra_headers.append(ctx->generate_basic_proxy_auth_header());
632632
}
633+
634+
// Add support for Basic authroization
635+
if (ctx->m_http_client->client_config().credentials().is_set())
636+
{
637+
extra_headers.append(ctx->generate_basic_auth_header());
638+
}
633639

634640
// Check user specified transfer-encoding.
635641
std::string transferencoding;
@@ -730,6 +736,25 @@ class asio_context : public request_context, public std::enable_shared_from_this
730736

731737
private:
732738

739+
utility::string_t generate_basic_auth_header()
740+
{
741+
utility::string_t header;
742+
743+
header.append(header_names::authorization);
744+
header.append(": Basic ");
745+
746+
auto credential_str = web::details::plaintext_string(new ::utility::string_t(m_http_client->client_config().credentials().username()));
747+
credential_str->append(":");
748+
credential_str->append(*m_http_client->client_config().credentials().decrypt());
749+
750+
std::vector<unsigned char> credentials_buffer(credential_str->begin(), credential_str->end());
751+
752+
header.append(utility::conversions::to_base64(credentials_buffer));
753+
header.append(CRLF);
754+
return header;
755+
}
756+
757+
733758
utility::string_t generate_basic_proxy_auth_header()
734759
{
735760
utility::string_t header;

0 commit comments

Comments
 (0)