blog-banner

Drupal Moodle User Integration

  • Drupal 7
  • Drupal Integration
  • Moodle Integration

Drupal Moodle SSO

Moodle is a free and open-source software learning management system written in PHP and distributed under the GNU General Public License. Moodle is used for blended learning, distance education, flipped classrooms, and other e-learning projects in schools, universities, workplaces, and other sectors.

Our main objective is that we wanted to manage all the users from Drupal i.e., use drupal as the front end for managing users. For this purpose, we have a moodle plugin and Drupal module. Drupal services is a moodle authorization plugin that allows for SSO between Drupal and Moodle. Moodle SSO provides the Drupal functionality required to allow the Moodle training management system to SSO share Drupal sessions.

In order to make SSO work, we need to ensure that sites can share cookies. Drupal and moodle sites should have urls like drupal.example.com and moodle.example.com. As mentioned earlier, sites should be able to share cookies. To make sites use a shared cookie, we need to set the value of $cookie_domain in a settings.php file on the drupal site. In our case, the site URLs were something like drupal.example.com and moodle.example.com. For these types of sub-domains, the cookie_domain value can be set like the below one:

$cookie_domain = ".example.com";

Note: The dot before "example.com" is necessary.

Let's start with the steps that need to follow for achieving SSO (single sign-on) between drupal and moodle:

1. Moodle site

  • Download the drupal services plugin based on your moodle version from here.
  • Then place the extracted folder in /auth directory of your moodle site. Don't forget to rename the folder as "drupalservices".
  • When you visit your Moodle site, you will be redirected to the drupal services plugin installation page. Finish the installation of the "drupalservices" plugin.
  • We need to enable Web services.
    • Go to Home - Site administration - Advanced features. Mark the Enable web services option. Click Save changes button on the bottom.
    • Go to Home - Site administration - Plugins - Web services - Manage protocols. Enable the REST protocol (by clicking on the marker in the Enable column). Click Save changes button on the bottom.
  • Configure Drupal services settings
    • Go to Home - Site administration - Plugins - Authentication - Drupal Services
    • Set Drupal Website URL to the Drupal URL (for example, drupal.example.com) which must be connected with Moodle.
    • Then map the fields from drupal to moodle. Don’t forget to map id number with drupal uid. This is very important.
    • Finally, fill in the details in User import/migration settings.

2. Drupal site

  • We need to install all the dependency modules of Moodle SSO.
  • Configure Moodle SSO
    • Most of the settings would be preconfigured. We need to ensure services settings are proper. Check if muser, moodlesso, login, logout are all enabled at /admin/structure/services/list/moodlesso/resources.
After doing all these configurations, we will be able to achieve the following things:
 
  • When we log into the Drupal site, we will be automatically logged into Moodle site with the same account.
  • If the same account is not present in moodle, it will be automatically created.
  • Similarly logging out of the moodle site will automatically log out of the drupal site as well.

We wanted to import all the users from moodle to drupal. For this, we created a custom local plugin based on web service. From the drupal site, we made a call to the web service function and got the list of all users in moodle. Using this list of users, we created them on the Drupal site.

The Drupal Moodle user integration is just a first step in the arena. We at Knackforge have worked on Course, Certificate integration between Moodle and Drupal. We would share that experience in the upcoming posts.

Get awesome tech content in your inbox