@@ -1024,8 +1024,9 @@ void rd_kafka_oidc_token_metadata_azure_imds_refresh_cb(
10241024
10251025 struct curl_slist * headers = NULL ;
10261026
1027- char * token_endpoint_url = NULL ;
1028- char * sub = NULL ;
1027+ const char * token_endpoint_url_initial = NULL ;
1028+ char * token_endpoint_url = NULL ;
1029+ char * sub = NULL ;
10291030
10301031 size_t extension_cnt ;
10311032 size_t extension_key_value_cnt = 0 ;
@@ -1034,45 +1035,39 @@ void rd_kafka_oidc_token_metadata_azure_imds_refresh_cb(
10341035
10351036 char * * extensions = NULL ;
10361037 char * * extension_key_value = NULL ;
1038+ char * query = NULL ;
10371039 static char * headers_array [] = {"Metadata: true" };
10381040
10391041 if (rd_kafka_terminating (rk ))
10401042 return ;
10411043
1042- if (rk -> rk_conf .sasl .oauthbearer_config &&
1043- !rk -> rk_conf .sasl .oauthbearer .metadata_authentication .query ) {
1044- size_t i , oauthbearer_config_cnt ;
1045- char * * config_pairs =
1046- rd_string_split (rk -> rk_conf .sasl .oauthbearer_config , ',' ,
1047- rd_true , & oauthbearer_config_cnt );
1048- for (i = 0 ; i < oauthbearer_config_cnt ; i ++ ) {
1049- char * config_pair = config_pairs [i ];
1050- char * query_pos = strstr (config_pair , "query=" );
1051- if (query_pos == config_pair ) {
1052- rk -> rk_conf .sasl .oauthbearer
1053- .metadata_authentication .query =
1054- query_pos + strlen ("query=" );
1055- break ;
1056- }
1044+ if (rk -> rk_conf .sasl .oauthbearer_config )
1045+ query = rd_kafka_conf_kv_get (
1046+ rk -> rk_conf .sasl .oauthbearer_config , "query" , ',' );
1047+ token_endpoint_url_initial =
1048+ rk -> rk_conf .sasl .oauthbearer .token_endpoint_url ;
1049+ if (!token_endpoint_url_initial )
1050+ token_endpoint_url_initial =
1051+ RD_KAFKA_SASL_OAUTHBEARER_METADATA_AUTHENTICATION_URL_AZURE_IMDS ;
1052+ if (query && * query ) {
1053+ token_endpoint_url = rd_http_get_params_append (
1054+ token_endpoint_url_initial , query );
1055+
1056+ if (token_endpoint_url == NULL ) {
1057+ rd_snprintf (
1058+ set_token_errstr , sizeof (set_token_errstr ),
1059+ "Failed to append params \"%s\" to token endpoint "
1060+ "URL \"%s\"" ,
1061+ query ,
1062+ rk -> rk_conf .sasl .oauthbearer .token_endpoint_url );
1063+ rd_kafka_log (rk , LOG_ERR , "OIDC" , "%s" ,
1064+ set_token_errstr );
1065+ rd_kafka_oauthbearer_set_token_failure (
1066+ rk , set_token_errstr );
1067+ goto done ;
10571068 }
1058- if (!rk -> rk_conf .sasl .oauthbearer .metadata_authentication .query )
1059- rk -> rk_conf .sasl .oauthbearer .metadata_authentication
1060- .query = "" ;
1061- }
1062-
1063- token_endpoint_url = rd_http_get_params_append (
1064- rk -> rk_conf .sasl .oauthbearer .token_endpoint_url ,
1065- rk -> rk_conf .sasl .oauthbearer .metadata_authentication .query );
1066- if (token_endpoint_url == NULL ) {
1067- rd_snprintf (
1068- set_token_errstr , sizeof (set_token_errstr ),
1069- "Failed to append params \"%s\" to token endpoint "
1070- "URL \"%s\"" ,
1071- rk -> rk_conf .sasl .oauthbearer .metadata_authentication .query ,
1072- rk -> rk_conf .sasl .oauthbearer .token_endpoint_url );
1073- rd_kafka_log (rk , LOG_ERR , "OIDC" , "%s" , set_token_errstr );
1074- rd_kafka_oauthbearer_set_token_failure (rk , set_token_errstr );
1075- goto done ;
1069+ } else {
1070+ token_endpoint_url = rd_strdup (token_endpoint_url_initial );
10761071 }
10771072
10781073 herr = rd_http_get_json (rk , token_endpoint_url , headers_array , 1 ,
@@ -1120,6 +1115,7 @@ void rd_kafka_oidc_token_metadata_azure_imds_refresh_cb(
11201115 RD_IF_FREE (extensions , rd_free );
11211116 RD_IF_FREE (extension_key_value , rd_free );
11221117 RD_IF_FREE (token_endpoint_url , rd_free );
1118+ RD_IF_FREE (query , rd_free );
11231119}
11241120
11251121/**
0 commit comments