Merge branch 'MDL-70282-oauth2_improve_error-311' of https://github.com/leonstr/moodle into MOODLE_311_STABLE

This commit is contained in:
Sara Arjona
2021-02-09 11:05:05 +01:00
4 changed files with 14 additions and 2 deletions
+3
View File
@@ -474,6 +474,9 @@ $string['notownerofkey'] = 'You are not owner of this key';
$string['nousers'] = 'No such user!';
$string['oauth1accesstoken'] = 'OAuth 1.0 error: We did not obtain the access token.';
$string['oauth1requesttoken'] = 'OAuth 1.0 error: We did not obtain the request token - the service provider may be temporarily down.';
$string['oauth2upgradetokenerror'] = 'Could not upgrade OAuth 2 token. HTTP status for remote endpoint: {$a}';
$string['oauth2refreshtokenerror'] = 'Could not refresh OAuth 2 token. HTTP status for remote endpoint: {$a}';
$string['oauth2refreshtokentaskerror'] = 'Could not refresh OAuth 2 token for one or more issuers. View task output for details.';
$string['onlyadmins'] = 'Only administrators can do that';
$string['onlyeditingteachers'] = 'Only editing teachers can do that';
$string['onlyeditown'] = 'You can only edit your own information';
+2 -1
View File
@@ -403,7 +403,8 @@ class client extends \oauth2_client {
}
if ($this->info['http_code'] !== 200) {
throw new moodle_exception('Could not upgrade oauth token');
$debuginfo = !empty($this->error) ? $this->error : $response;
throw new moodle_exception('oauth2refreshtokenerror', 'core_error', '', $this->info['http_code'], $debuginfo);
}
$r = json_decode($response);
@@ -85,6 +85,7 @@ class refresh_system_tokens_task extends scheduled_task {
*/
public function execute() {
$issuers = \core\oauth2\api::get_all_issuers();
$tasksuccess = true;
foreach ($issuers as $issuer) {
if ($issuer->is_system_account_connected()) {
try {
@@ -92,13 +93,19 @@ class refresh_system_tokens_task extends scheduled_task {
// Returns false or throws a moodle_exception on error.
$success = \core\oauth2\api::get_system_oauth_client($issuer);
} catch (moodle_exception $e) {
mtrace($e->getMessage());
$success = false;
}
if ($success === false) {
$this->notify_admins($issuer);
$tasksuccess = false;
}
}
}
if (!$tasksuccess) {
throw new moodle_exception('oauth2refreshtokentaskerror', 'core_error');
}
}
}
+2 -1
View File
@@ -568,7 +568,8 @@ abstract class oauth2_client extends curl {
}
if ($this->info['http_code'] !== 200) {
throw new moodle_exception('Could not upgrade oauth token');
$debuginfo = !empty($this->error) ? $this->error : $response;
throw new moodle_exception('oauth2upgradetokenerror', 'core_error', '', $this->info['http_code'], $debuginfo);
}
$r = json_decode($response);