]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: Take http_client_request_url_str in use for oauth2 requests.
authorSergey Kitov <sergey.kitov@open-xchange.com>
Thu, 31 Jan 2019 08:36:49 +0000 (10:36 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Thu, 21 Mar 2019 08:02:52 +0000 (10:02 +0200)
src/lib-oauth2/oauth2-introspect.c
src/lib-oauth2/oauth2-refresh.c
src/lib-oauth2/oauth2-token-validate.c

index 0109eda71886fcfd63454fe4411ff6ad602660a4..9a2784e0f2c98bc8b55a36914bc6c928bf2997cd 100644 (file)
@@ -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",
index 426afb96f08b68622b07c00d5af1924e59e212d9..12336527161263a0db189334e2d379a41ca16a13 100644 (file)
@@ -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");
 
index 2b7f5b05b73cee66f3fd4579bfc171e5e942c148..ca6b1c37e1a1a4c146279e746faeb547aeeb562e 100644 (file)
@@ -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",