@@ -789,6 +789,7 @@ class ClientImpl {
789
789
void set_write_timeout (time_t sec, time_t usec = 0 );
790
790
791
791
void set_basic_auth (const char *username, const char *password);
792
+ void set_bearer_token_auth (const char *token);
792
793
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
793
794
void set_digest_auth (const char *username, const char *password);
794
795
#endif
@@ -804,6 +805,7 @@ class ClientImpl {
804
805
805
806
void set_proxy (const char *host, int port);
806
807
void set_proxy_basic_auth (const char *username, const char *password);
808
+ void set_proxy_bearer_token_auth (const char *token);
807
809
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
808
810
void set_proxy_digest_auth (const char *username, const char *password);
809
811
#endif
@@ -849,6 +851,7 @@ class ClientImpl {
849
851
850
852
std::string basic_auth_username_;
851
853
std::string basic_auth_password_;
854
+ std::string bearer_token_auth_token_;
852
855
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
853
856
std::string digest_auth_username_;
854
857
std::string digest_auth_password_;
@@ -870,6 +873,7 @@ class ClientImpl {
870
873
871
874
std::string proxy_basic_auth_username_;
872
875
std::string proxy_basic_auth_password_;
876
+ std::string proxy_bearer_token_auth_token_;
873
877
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
874
878
std::string proxy_digest_auth_username_;
875
879
std::string proxy_digest_auth_password_;
@@ -887,6 +891,7 @@ class ClientImpl {
887
891
write_timeout_usec_ = rhs.write_timeout_usec_ ;
888
892
basic_auth_username_ = rhs.basic_auth_username_ ;
889
893
basic_auth_password_ = rhs.basic_auth_password_ ;
894
+ bearer_token_auth_token_ = rhs.bearer_token_auth_token_ ;
890
895
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
891
896
digest_auth_username_ = rhs.digest_auth_username_ ;
892
897
digest_auth_password_ = rhs.digest_auth_password_ ;
@@ -902,6 +907,7 @@ class ClientImpl {
902
907
proxy_port_ = rhs.proxy_port_ ;
903
908
proxy_basic_auth_username_ = rhs.proxy_basic_auth_username_ ;
904
909
proxy_basic_auth_password_ = rhs.proxy_basic_auth_password_ ;
910
+ proxy_bearer_token_auth_token_ = rhs.proxy_bearer_token_auth_token_ ;
905
911
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
906
912
proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_ ;
907
913
proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_ ;
@@ -1046,6 +1052,7 @@ class Client {
1046
1052
void set_write_timeout (time_t sec, time_t usec = 0 );
1047
1053
1048
1054
void set_basic_auth (const char *username, const char *password);
1055
+ void set_bearer_token_auth (const char *token);
1049
1056
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1050
1057
void set_digest_auth (const char *username, const char *password);
1051
1058
#endif
@@ -1061,6 +1068,7 @@ class Client {
1061
1068
1062
1069
void set_proxy (const char *host, int port);
1063
1070
void set_proxy_basic_auth (const char *username, const char *password);
1071
+ void set_proxy_bearer_token_auth (const char *token);
1064
1072
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1065
1073
void set_proxy_digest_auth (const char *username, const char *password);
1066
1074
#endif
@@ -3320,6 +3328,14 @@ make_basic_authentication_header(const std::string &username,
3320
3328
return std::make_pair (key, field);
3321
3329
}
3322
3330
3331
+ inline std::pair<std::string, std::string>
3332
+ make_bearer_token_authentication_header (const std::string &token,
3333
+ bool is_proxy = false ) {
3334
+ auto field = " Bearer " + token;
3335
+ auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
3336
+ return std::make_pair (key, field);
3337
+ }
3338
+
3323
3339
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3324
3340
inline std::pair<std::string, std::string> make_digest_authentication_header (
3325
3341
const Request &req, const std::map<std::string, std::string> &auth,
@@ -4761,6 +4777,16 @@ inline bool ClientImpl::write_request(Stream &strm, const Request &req,
4761
4777
proxy_basic_auth_username_, proxy_basic_auth_password_, true ));
4762
4778
}
4763
4779
4780
+ if (!bearer_token_auth_token_.empty ()) {
4781
+ headers.insert (make_bearer_token_authentication_header (
4782
+ bearer_token_auth_token_, false ));
4783
+ }
4784
+
4785
+ if (!proxy_bearer_token_auth_token_.empty ()) {
4786
+ headers.insert (make_bearer_token_authentication_header (
4787
+ proxy_bearer_token_auth_token_, true ));
4788
+ }
4789
+
4764
4790
detail::write_headers (bstrm, req, headers);
4765
4791
4766
4792
// Flush buffer
@@ -5253,6 +5279,10 @@ inline void ClientImpl::set_basic_auth(const char *username,
5253
5279
basic_auth_password_ = password;
5254
5280
}
5255
5281
5282
+ inline void ClientImpl::set_bearer_token_auth (const char *token) {
5283
+ bearer_token_auth_token_ = token;
5284
+ }
5285
+
5256
5286
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
5257
5287
inline void ClientImpl::set_digest_auth (const char *username,
5258
5288
const char *password) {
@@ -5288,6 +5318,10 @@ inline void ClientImpl::set_proxy_basic_auth(const char *username,
5288
5318
proxy_basic_auth_password_ = password;
5289
5319
}
5290
5320
5321
+ inline void ClientImpl::set_proxy_bearer_token_auth (const char *token) {
5322
+ proxy_bearer_token_auth_token_ = token;
5323
+ }
5324
+
5291
5325
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
5292
5326
inline void ClientImpl::set_proxy_digest_auth (const char *username,
5293
5327
const char *password) {
@@ -6186,6 +6220,9 @@ inline void Client::set_write_timeout(time_t sec, time_t usec) {
6186
6220
inline void Client::set_basic_auth (const char *username, const char *password) {
6187
6221
cli_->set_basic_auth (username, password);
6188
6222
}
6223
+ inline void Client::set_bearer_token_auth (const char *token) {
6224
+ cli_->set_bearer_token_auth (token);
6225
+ }
6189
6226
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
6190
6227
inline void Client::set_digest_auth (const char *username,
6191
6228
const char *password) {
@@ -6213,6 +6250,9 @@ inline void Client::set_proxy_basic_auth(const char *username,
6213
6250
const char *password) {
6214
6251
cli_->set_proxy_basic_auth (username, password);
6215
6252
}
6253
+ inline void Client::set_proxy_bearer_token_auth (const char *token) {
6254
+ cli_->set_proxy_bearer_token_auth (token);
6255
+ }
6216
6256
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
6217
6257
inline void Client::set_proxy_digest_auth (const char *username,
6218
6258
const char *password) {
0 commit comments