Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-65918

Error during first OAuth2 login for existing account (Call to undefined function auth_oauth2\profile_save_data())

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      Setup
      1. Manually create a user with a Gmail email address. You may also edit an existing user's email to the Gmail email address. Let's call this user s1.
      2. Go to "Site administration / Plugins / Authentication / Manage authentication" and enable the "OAuth 2" authentication plugin
      3. Set up a Google OAuth2 service. Take note of the Client ID and Client secret.
      4. Go to "Site administration / Server / OAuth 2 services"
      5. Create a new Google service
      6. Enter a name, the Client ID and Client secret
      7. Make sure "Show on login page" is ticked.
      8. Make sure "Require email verification" is unticked.
      9. Save the changes.
      10. Open a terminal and tail PHP's error log. e.g. if your error log is in "/var/log/apache2/error.log":

        tail -f /var/log/apache2/error.log
        

      Test
      1. On a different browser session, log in via Google using s1's Google account.
      2. When you get logged in, confirm that you don't see any error message.
      3. Check the terminal output of the "tail" command.
      4. Confirm that you don't see any errors as well about the undefined function.
      Show
      Setup Manually create a user with a Gmail email address. You may also edit an existing user's email to the Gmail email address. Let's call this user s1. Go to " Site administration / Plugins / Authentication / Manage authentication " and enable the " OAuth 2 " authentication plugin Set up a Google OAuth2 service . Take note of the Client ID and Client secret. Go to " Site administration / Server / OAuth 2 services " Create a new Google service Enter a name, the Client ID and Client secret Make sure " Show on login page " is ticked. Make sure " Require email verification " is unticked. Save the changes. Open a terminal and tail PHP's error log. e.g. if your error log is in " /var/log/apache2/error.log ": tail -f /var/log/apache2/error.log Test On a different browser session, log in via Google using s1's Google account. When you get logged in, confirm that you don't see any error message. Check the terminal output of the " tail " command. Confirm that you don't see any errors as well about the undefined function.
    • Affected Branches:
      MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE
    • Pull 3.7 Branch:
    • Pull Master Branch:
      MDL-65918-master
    • Story Points:
      1
    • Sprint:
      Sprint 2 - Experimental

      Description

      When I set up an account with the "oauth2" auth type (using a custom OAuth2 issuer, in this case), the first time the user logs in with OAuth2 she will receive the following error:

      Exception - Call to undefined function auth_oauth2\profile_save_data()

      Stack trace:

      • line 354 of /auth/oauth2/classes/auth.php: Error thrown
      • line 536 of /auth/oauth2/classes/auth.php: call to auth_oauth2\auth->update_user()
      • line 49 of /auth/oauth2/login.php: call to auth_oauth2\auth->complete_login()

       

      The problem seems to have been introduced in this commit from December 2018, when the call to `profile_save_data()` was added without also requiring `user/profile/lib.php`:  https://github.com/moodle/moodle/commit/e2b812fc4028ebf40c4fbb1cdad293a825d84079#diff-53adc3a153341eaa9eb2d5e086e88519R354

       

      A fix that worked for me was to simply add

       

      require_once($CFG->dirroot.'/user/profile/lib.php'); 
      

      under the other require_once() statements at the top of auth/oauth2/classes/auth.php

       

      Unfortunately I don't anticipate having the time to go through the process of becoming a new contributor and submitting code for peer review anytime soon. I hope this is a good enough start to get this fixed in a future release.

        Attachments

          Activity

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Sep/19

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 2 minutes
                4h 2m