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
This commit is contained in:
Jorge López Pérez
2022-08-09 19:13:58 +02:00
committed by GitHub
parent 864e0710a3
commit e808fba4f8
2 changed files with 8 additions and 5 deletions

View File

@@ -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;

View File

@@ -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, [