@@ -67,6 +67,11 @@ struct flb_config_map oauth2_config_map[] = {
6767 0 , FLB_TRUE , offsetof(struct flb_oauth2_config , client_secret ),
6868 "OAuth2 client_secret"
6969 },
70+ {
71+ FLB_CONFIG_MAP_STR , "oauth2.user_agent" , NULL ,
72+ 0 , FLB_TRUE , offsetof(struct flb_oauth2_config , user_agent ),
73+ "Optional User-Agent header for OAuth2 token requests"
74+ },
7075 {
7176 FLB_CONFIG_MAP_STR , "oauth2.scope" , NULL ,
7277 0 , FLB_TRUE , offsetof(struct flb_oauth2_config , scope ),
@@ -185,6 +190,7 @@ static void oauth2_apply_defaults(struct flb_oauth2_config *cfg)
185190 cfg -> token_url = NULL ;
186191 cfg -> client_id = NULL ;
187192 cfg -> client_secret = NULL ;
193+ cfg -> user_agent = NULL ;
188194 cfg -> scope = NULL ;
189195 cfg -> audience = NULL ;
190196 cfg -> resource = NULL ;
@@ -243,6 +249,15 @@ static int oauth2_clone_config(struct flb_oauth2_config *dst,
243249 }
244250 }
245251
252+ if (src -> user_agent ) {
253+ dst -> user_agent = flb_sds_create (src -> user_agent );
254+ if (!dst -> user_agent ) {
255+ flb_errno ();
256+ flb_oauth2_config_destroy (dst );
257+ return -1 ;
258+ }
259+ }
260+
246261 if (src -> scope ) {
247262 dst -> scope = flb_sds_create (src -> scope );
248263 if (!dst -> scope ) {
@@ -324,6 +339,8 @@ void flb_oauth2_config_destroy(struct flb_oauth2_config *cfg)
324339 cfg -> client_id = NULL ;
325340 flb_sds_destroy (cfg -> client_secret );
326341 cfg -> client_secret = NULL ;
342+ flb_sds_destroy (cfg -> user_agent );
343+ cfg -> user_agent = NULL ;
327344 flb_sds_destroy (cfg -> scope );
328345 cfg -> scope = NULL ;
329346 flb_sds_destroy (cfg -> audience );
@@ -1114,6 +1131,14 @@ static int oauth2_http_request(struct flb_oauth2 *ctx, flb_sds_t body)
11141131 FLB_OAUTH2_HTTP_ENCODING ,
11151132 sizeof (FLB_OAUTH2_HTTP_ENCODING ) - 1 );
11161133
1134+ if (ctx -> cfg .user_agent ) {
1135+ flb_http_add_header (c ,
1136+ "User-Agent" ,
1137+ 10 ,
1138+ ctx -> cfg .user_agent ,
1139+ flb_sds_len (ctx -> cfg .user_agent ));
1140+ }
1141+
11171142 if (ctx -> cfg .auth_method == FLB_OAUTH2_AUTH_METHOD_BASIC &&
11181143 ctx -> cfg .client_id && ctx -> cfg .client_secret ) {
11191144 ret = flb_http_basic_auth (c , ctx -> cfg .client_id , ctx -> cfg .client_secret );
0 commit comments