error/Could not upgrade oauth token - Moodle 3.9

Re: error/Could not upgrade oauth token - Moodle 3.9

by Leon Stringer -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers

The message in Moodle doesn't include enough information to help troubleshoot these kinds of errors. You can modify the file lib/oauthlib.php as follows changing lines 570-572 from:

        if ($this->info['http_code'] !== 200) {
            throw new moodle_exception('Could not upgrade oauth token');
        }

to:

        if ($this->info['http_code'] !== 200) {
            if ($this->error) {
                $error = $this->error;
            } else if ($this->info['http_code']) {
                $error = "HTTP status: {$this->info['http_code']}";
            }

            throw new moodle_exception('Could not upgrade token', 'core_error', '', $response, $error);
        }

Then enable debugging (Site administration ▸ Development ▸ Debugging, Debug messages: DEVELOPER and Display debug messages: Yes). Hopefully you will see more detail including the error the Microsoft OAuth 2 service is sending.

Average of ratings: Useful (1)