Merge branch 'MDL-71119-39' of git://github.com/sarjona/moodle into MOODLE_39_STABLE

This commit is contained in:
Jake Dallimore 2021-04-15 08:33:03 +08:00
commit ea90581cb1
3 changed files with 11 additions and 3 deletions

View file

@ -42,6 +42,10 @@ if ($persistedissuer) {
$returnurl = new moodle_url('/badges/backpack-connect.php', $returnurl = new moodle_url('/badges/backpack-connect.php',
['action' => 'authorization', 'sesskey' => sesskey()]); ['action' => 'authorization', 'sesskey' => sesskey()]);
// If scope is not passed as parameter, use the issuer supported scopes.
if (empty($scope)) {
$scope = $issuer->get('scopessupported');
}
$client = new core_badges\oauth2\client($issuer, $returnurl, $scope, $externalbackpack); $client = new core_badges\oauth2\client($issuer, $returnurl, $scope, $externalbackpack);
if ($client) { if ($client) {
if (!$client->is_logged_in()) { if (!$client->is_logged_in()) {

View file

@ -222,6 +222,7 @@ class client extends \core\oauth2\client {
$callbackurl = self::callback_url(); $callbackurl = self::callback_url();
if ($granttype == 'authorization_code') { if ($granttype == 'authorization_code') {
$this->basicauth = true;
$params = array('code' => $code, $params = array('code' => $code,
'grant_type' => $granttype, 'grant_type' => $granttype,
'redirect_uri' => $callbackurl->out(false), 'redirect_uri' => $callbackurl->out(false),
@ -236,7 +237,7 @@ class client extends \core\oauth2\client {
); );
} }
if ($this->basicauth) { if ($this->basicauth) {
$idsecret = urlencode($this->clientid) . ':' . urlencode($this->clientsecret); $idsecret = $this->clientid . ':' . $this->clientsecret;
$this->setHeader('Authorization: Basic ' . base64_encode($idsecret)); $this->setHeader('Authorization: Basic ' . base64_encode($idsecret));
} else { } else {
$params['client_id'] = $this->clientid; $params['client_id'] = $this->clientid;
@ -244,11 +245,13 @@ class client extends \core\oauth2\client {
} }
// Requests can either use http GET or POST. // Requests can either use http GET or POST.
$response = $this->post($this->token_url(), $this->build_post_data($params)); $response = $this->post($this->token_url(), $this->build_post_data($params));
$r = json_decode($response);
if ($this->info['http_code'] !== 200) { 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);
if (is_null($r)) { if (is_null($r)) {
throw new moodle_exception("Could not decode JSON token response"); throw new moodle_exception("Could not decode JSON token response");
} }

View file

@ -468,6 +468,7 @@ $string['notownerofkey'] = 'You are not owner of this key';
$string['nousers'] = 'No such user!'; $string['nousers'] = 'No such user!';
$string['oauth1accesstoken'] = 'OAuth 1.0 error: We did not obtain the access token.'; $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['oauth1requesttoken'] = 'OAuth 1.0 error: We did not obtain the request token - the service provider may be temporarily down.';
$string['oauth2refreshtokenerror'] = 'Could not refresh OAuth 2 token. HTTP status for remote endpoint: {$a}';
$string['onlyadmins'] = 'Only administrators can do that'; $string['onlyadmins'] = 'Only administrators can do that';
$string['onlyeditingteachers'] = 'Only editing teachers can do that'; $string['onlyeditingteachers'] = 'Only editing teachers can do that';
$string['onlyeditown'] = 'You can only edit your own information'; $string['onlyeditown'] = 'You can only edit your own information';