Search code examples
httpoauth-2.0openidmoodle

Could not upgrade OAuth 2 token. HTTP status for remote endpoint: {$a} in moodle 4.2


I used the custom service : OpenID for SSO. I configured the endpoints, user field mappings and rest of the things. But when I tried to login with the username and password it returns with the error mentioned above. I have gone through the moodle documents but could not get the result. The error is : Could not upgrade OAuth 2 token. HTTP status for remote endpoint: {$a}

I am using the Moodle Version 4.2

I tried to get the solution from OAuth2 Moodle , OAuth Services, Single Sign Off

Trace after opening debugging mode

Error: mdb->get_record() found more than one record!
    line 1691 of /lib/dml/moodle_database.php: call to debugging()
    line 1651 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
    line 1630 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
    line 582 of /lib/datalib.php: call to moodle_database->get_record()
    line 794 of /lib/setup.php: call to get_site()
    line 41 of /config.php: call to require_once()
    line 31 of /admin/oauth2callback.php: call to require_once()

Please find the screenshot of error at below link:

error regarding oauth


Solution

  • Can you switch on debugging and copy and paste the trace into the question

    Edit config.php and insert the following

    // Force a debugging mode regardless the settings in the site administration
    @error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS!
    @ini_set('display_errors', '1');    // NOT FOR PRODUCTION SERVERS!
    $CFG->debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!
    $CFG->debugdisplay = 1;             // NOT FOR PRODUCTION SERVERS!
    

    EDIT :

    Looks like you are using Moodle 4.2 ?

    This line

    line 582 of /lib/datalib.php: call to moodle_database->get_record()
    

    Has this code

    if ($course = $DB->get_record('course', array('category'=>0))) {
    

    Looks like you have more than one course with a category of 0 - only the site course should be using that category

    Check the course table and change the category to something else for the non-site course - the site course id is probably 1, so keep that as 0

    SELECT *
    FROM mdl_course
    WHERE category = 0