From e808fba4f89702a5f07abdb452bdcb802541b93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20L=C3=B3pez=20P=C3=A9rez?= Date: Tue, 9 Aug 2022 19:13:58 +0200 Subject: Initialize HTTP client using get_http_client() for OAuth requests (#8666) * Initialize HTTP client using get_http_client() for OAuth requests * Add new oauth_timeout setting --- config/defaults.inc.php | 3 +++ program/include/rcmail_oauth.php | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config/defaults.inc.php b/config/defaults.inc.php index 3794e99da..afdeda6f3 100644 --- a/config/defaults.inc.php +++ b/config/defaults.inc.php @@ -358,6 +358,9 @@ $config['oauth_token_uri'] = null; // Optional: Endpoint to query user identity if not provided in auth response $config['oauth_identity_uri'] = null; +// Optional: timeout for HTTP requests to OAuth server +$config['oauth_timeout'] = 10; + // Optional: disable SSL certificate check on HTTP requests to OAuth server // See http://docs.guzzlephp.org/en/stable/request-options.html#verify for possible values $config['oauth_verify_peer'] = true; diff --git a/program/include/rcmail_oauth.php b/program/include/rcmail_oauth.php index 7d0fca84b..b2f954c7e 100644 --- a/program/include/rcmail_oauth.php +++ b/program/include/rcmail_oauth.php @@ -17,7 +17,6 @@ +-----------------------------------------------------------------------+ */ -use GuzzleHttp\Client; use GuzzleHttp\MessageFormatter; use GuzzleHttp\Exception\RequestException; @@ -76,6 +75,7 @@ class rcmail_oauth 'identity_uri' => $this->rcmail->config->get('oauth_identity_uri'), 'identity_fields' => $this->rcmail->config->get('oauth_identity_fields', ['email']), 'scope' => $this->rcmail->config->get('oauth_scope'), + 'timeout' => $this->rcmail->config->get('oauth_timeout', 10), 'verify_peer' => $this->rcmail->config->get('oauth_verify_peer', true), 'auth_parameters' => $this->rcmail->config->get('oauth_auth_parameters', []), 'login_redirect' => $this->rcmail->config->get('oauth_login_redirect', false), @@ -219,8 +219,8 @@ class rcmail_oauth } // send token request to get a real access token for the given auth code - $client = new Client([ - 'timeout' => 10.0, + $client = rcube::get_instance()->get_http_client([ + 'timeout' => $this->options['timeout'], 'verify' => $this->options['verify_peer'], ]); @@ -366,8 +366,8 @@ class rcmail_oauth // send token request to get a real access token for the given auth code try { - $client = new Client([ - 'timeout' => 10.0, + $client = rcube::get_instance()->get_http_client([ + 'timeout' => $this->options['timeout'], 'verify' => $this->options['verify_peer'], ]); $response = $client->post($oauth_token_uri, [ -- cgit v1.2.3