blog-banner

Drupal Moodle Integration

  • Drupal 7
  • Drupal Planet

Drupal Moodle

 

We got an interesting requirement, to integrate Drupal and Moodle (Totara actually) in order for a nice combination of CMS features and LMS features. The integration should follow SSO, where a user logged in Drupal should automatically be logged in to Moodle.

We decided to use existing plugins as much as possible along with additional customization wherever needed.

To accomplish SSO between Drupal and moodle, we used moodle-drupalservices on Moodle side and Moodle SSO on the Drupal side. Alongside we developed an additional two plugins one to support user import and the other for course integration. Our client had to import the previous set of users during the initial setup into Moodle (Totara), which needs to be synchronized back to Drupal while normal SSO flow is Drupal to Moodle.

High-level Diagram

Drupal moodle integration

Drupal services (Moodle contrib plugin)

  • Moodle Drupal services plugin allows for SSO between Drupal and Moodle. All users are maintained on Drupal and Moodle authenticates via REST to the drupal Services module.

  • Workflow of this plugin

    • Checks to see if there is a valid Drupal session cookie.

    • If so, tries to connect to Drupal services and retrieve drupal user info.

    • If the Drupal user is valid and the user exists in Moodle then the user is logged into Moodle. During this login, user field values from Drupal are automatically updated in Moodle.

    • Upon logout, the user is also logged out from drupal.

  • This plugin does not sync users by username but instead by uid (drupal side) and ID number (Moodle side). This allows the username to change on drupal and prevents moodle from creating a new user if the username changes. This does mean that the ID number field must be locked or you could have big problems and possible security issues.

  • To know more about the installation of this plugin, kindly take a look here

  • We have added some additional code to ensure SSO is seamless even when a user is accessing the site with session restoring and for custom profile fields synchronization.

Moodle SSO (Drupal contrib module)

  • Moodle SSO provides the Drupal functionality required to allow the Moodle training management system to SSO share Drupal sessions.

  • SSO can only happen between sites that can share cookies. This means the following configurations will work:

moodle.example.com & drupal.example.com

  • In order for this to work, the $cookie_domain value located in the settings.php file on the drupal site must be modified to use a shared cookie.

          $cookie_domain = ".example.com";

          Note the leading dot before example.com

  • To know more about the installation of this plugin, kindly take a look here

User export (Custom plugin)

This plugin exposes all users who were not yet synchronized with Drupal users. From the Drupal side, we had an interface to pull those users into the Drupal system.

Course integration (Custom plugin)

The main goal of the project is to have courses integrated with content in Drupal nodes. We developed a custom plugin in Moodle side that will expose all courses (or user courses) along with necessary details like course progress, start date. Then on the Drupal side, those courses are bound to a custom field type that admin users can use to associate with course content. For a normal user, it will show course progress in a dashboard with all the necessary details said above.

Certificate integration

Inside the moodle course integration plugin, we had an additional API to transfer certificate URLs that are fetched and shown in the Drupal dashboard.

Notes:

  • In order to support multiple attempts with updated certificate generation, we had used certification feature of Totara, which I ignored here for simplicity.
  • The integration is working smoothly for 4+ months as of now. We had to tackle a lot of things to ensure it is working perfectly though I could not mention everything here. Feel free to let me know if you need some details.
Get awesome tech content in your inbox