Refresh oauth access token in 'refresh' plugin hook (#8224)

This commit is contained in:
Thomas Bruederli
2021-12-28 17:21:11 +01:00
parent 6564b7b32c
commit 841bead50a

View File

@@ -97,6 +97,7 @@ class rcmail_oauth
$this->rcmail->plugins->register_hook('logout_after', [$this, 'logout_after']);
$this->rcmail->plugins->register_hook('login_failed', [$this, 'login_failed']);
$this->rcmail->plugins->register_hook('unauthenticated', [$this, 'unauthenticated']);
$this->rcmail->plugins->register_hook('refresh', [$this, 'refresh']);
}
}
@@ -450,7 +451,7 @@ class rcmail_oauth
*/
protected function check_token_validity($token)
{
if ($token['expires'] < time() && isset($token['refresh_token'])) {
if ($token['expires'] < time() && isset($token['refresh_token']) && empty($this->last_error)) {
$this->refresh_access_token($token);
}
}
@@ -558,4 +559,18 @@ class rcmail_oauth
return $options;
}
/**
* Callback for 'refresh' hook
*
* @param array $options
* @return void
*/
public function refresh($options)
{
if (isset($_SESSION['oauth_token'])) {
$this->check_token_validity($_SESSION['oauth_token']);
}
}
}