From: Sergey Kitov Date: Thu, 31 Jan 2019 08:36:49 +0000 (+0200) Subject: lib-oauth2: Take http_client_request_url_str in use for oauth2 requests. X-Git-Tag: 2.3.6~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=671eee17b6a9d3598c4de7ff10be8bf6113f499c;p=thirdparty%2Fdovecot%2Fcore.git lib-oauth2: Take http_client_request_url_str in use for oauth2 requests. --- diff --git a/src/lib-oauth2/oauth2-introspect.c b/src/lib-oauth2/oauth2-introspect.c index 0109eda718..9a2784e0f2 100644 --- a/src/lib-oauth2/oauth2-introspect.c +++ b/src/lib-oauth2/oauth2-introspect.c @@ -57,15 +57,6 @@ oauth2_introspect_response(const struct http_response *response, } } -static void oauth2_introspection_delayed_error(struct oauth2_request *req) -{ - struct oauth2_introspection_result fail = { - .success = FALSE, - .error = req->delayed_error - }; - oauth2_introspection_callback(req, &fail); -} - #undef oauth2_introspection_start struct oauth2_request* oauth2_introspection_start(const struct oauth2_settings *set, @@ -78,8 +69,6 @@ oauth2_introspection_start(const struct oauth2_settings *set, pool_t pool = pool_alloconly_create_clean("oauth2 introspection", 1024); struct oauth2_request *req = p_new(pool, struct oauth2_request, 1); - struct http_url *url; - const char *error; req->pool = pool; req->set = set; @@ -93,19 +82,10 @@ oauth2_introspection_start(const struct oauth2_settings *set, http_url_escape_param(enc, input->token); } - if (http_url_parse(str_c(enc), NULL, HTTP_URL_ALLOW_USERINFO_PART, pool, - &url, &error) < 0) { - req->delayed_error = p_strdup_printf(pool, - "http_url_parse(%s) failed: %s", str_c(enc), error); - req->to_delayed_error = timeout_add_short(0, - oauth2_introspection_delayed_error, req); - return req; - } - if (set->introspection_mode == INTROSPECTION_MODE_POST) { - req->req = http_client_request_url(req->set->client, "POST", url, - oauth2_introspect_response, - req); + req->req = http_client_request_url_str(req->set->client, "POST", str_c(enc), + oauth2_introspect_response, + req); /* add token */ enc = t_str_new(strlen(input->token)+6); str_append(enc, "token="); @@ -114,14 +94,13 @@ oauth2_introspection_start(const struct oauth2_settings *set, "application/x-www-form-urlencoded"); http_client_request_set_payload_data(req->req, enc->data, enc->used); } else { - req->req = http_client_request_url(req->set->client, "GET", url, - oauth2_introspect_response, - req); + req->req = http_client_request_url_str(req->set->client, "GET", str_c(enc), + oauth2_introspect_response, + req); } - if (url->user != NULL) - http_client_request_set_auth_simple(req->req, url->user, url->password); - else if (set->introspection_mode == INTROSPECTION_MODE_GET_AUTH) + if (http_client_request_get_origin_url(req->req)->user == NULL && + set->introspection_mode == INTROSPECTION_MODE_GET_AUTH) http_client_request_add_header(req->req, "Authorization", t_strdup_printf("Bearer %s", diff --git a/src/lib-oauth2/oauth2-refresh.c b/src/lib-oauth2/oauth2-refresh.c index 426afb96f0..1233652716 100644 --- a/src/lib-oauth2/oauth2-refresh.c +++ b/src/lib-oauth2/oauth2-refresh.c @@ -97,15 +97,6 @@ oauth2_refresh_response(const struct http_response *response, } } -static void oauth2_refresh_delayed_error(struct oauth2_request *req) -{ - struct oauth2_refresh_result fail = { - .success = FALSE, - .error = req->delayed_error - }; - oauth2_refresh_callback(req, &fail); -} - #undef oauth2_refresh_start struct oauth2_request* oauth2_refresh_start(const struct oauth2_settings *set, @@ -118,27 +109,15 @@ oauth2_refresh_start(const struct oauth2_settings *set, pool_t pool = pool_alloconly_create_clean("oauth2 refresh", 1024); struct oauth2_request *req = p_new(pool, struct oauth2_request, 1); - struct http_url *url; - const char *error; req->pool = pool; req->set = set; req->re_callback = callback; req->re_context = context; - - if (http_url_parse(req->set->refresh_url, NULL, HTTP_URL_ALLOW_USERINFO_PART, - pool, &url, &error) < 0) { - req->delayed_error = p_strdup_printf(pool, - "http_url_parse(%s) failed: %s", - req->set->refresh_url, error); - req->to_delayed_error = timeout_add_short(0, - oauth2_refresh_delayed_error, req); - return req; - } - - req->req = http_client_request_url(req->set->client, "POST", url, - oauth2_refresh_response, + req->req = http_client_request_url_str(req->set->client, "POST", + req->set->refresh_url, + oauth2_refresh_response, req); string_t *payload = str_new(req->pool, 128); str_append(payload, "client_secret="); @@ -150,9 +129,6 @@ oauth2_refresh_start(const struct oauth2_settings *set, struct istream *is = i_stream_create_from_string(payload); - if (url->user != NULL) - http_client_request_set_auth_simple(req->req, url->user, url->password); - http_client_request_add_header(req->req, "Content-Type", "application/x-www-form-urlencoded"); diff --git a/src/lib-oauth2/oauth2-token-validate.c b/src/lib-oauth2/oauth2-token-validate.c index 2b7f5b05b7..ca6b1c37e1 100644 --- a/src/lib-oauth2/oauth2-token-validate.c +++ b/src/lib-oauth2/oauth2-token-validate.c @@ -86,15 +86,6 @@ oauth2_token_validate_response(const struct http_response *response, } } -static void oauth2_token_validation_delayed_error(struct oauth2_request *req) -{ - struct oauth2_token_validation_result fail = { - .success = FALSE, - .error = req->delayed_error - }; - oauth2_token_validation_callback(req, &fail); -} - #undef oauth2_token_validation_start struct oauth2_request* oauth2_token_validation_start(const struct oauth2_settings *set, @@ -104,9 +95,6 @@ oauth2_token_validation_start(const struct oauth2_settings *set, { i_assert(oauth2_valid_token(input->token)); - struct http_url *url; - const char *error; - pool_t pool = pool_alloconly_create_clean("oauth2 token_validation", 1024); struct oauth2_request *req = p_new(pool, struct oauth2_request, 1); @@ -120,22 +108,12 @@ oauth2_token_validation_start(const struct oauth2_settings *set, str_append(enc, req->set->tokeninfo_url); http_url_escape_param(enc, input->token); - if (http_url_parse(str_c(enc), NULL, HTTP_URL_ALLOW_USERINFO_PART, pool, - &url, &error) < 0) { - req->delayed_error = p_strdup_printf(pool, - "http_url_parse(%s) failed: %s", str_c(enc), error); - req->to_delayed_error = timeout_add_short(0, - oauth2_token_validation_delayed_error, req); - return req; - } - - req->req = http_client_request_url(req->set->client, "GET", url, - oauth2_token_validate_response, - req); + req->req = http_client_request_url_str(req->set->client, "GET", str_c(enc), + oauth2_token_validate_response, + req); - if (url->user != NULL) - http_client_request_set_auth_simple(req->req, url->user, url->password); - else + if (http_client_request_get_origin_url(req->req)->user == NULL && + set->introspection_mode == INTROSPECTION_MODE_GET_AUTH) http_client_request_add_header(req->req, "Authorization", t_strdup_printf("Bearer %s",