Drupal Moodle user integration
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 classroom 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 url 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 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 type 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 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 the drupalservices 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 idnumber with drupal uid. This is very important.
Finally, fill the details in User import/migration settings.
- 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.
- When we log into 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 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 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 in 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.