Maintained by Picture of Sixto Martin GarciaSixto Martin Garcia
SAML Authentication plugin based on the simplesamlphp software. (Also install the SAML Enrolment plugin if you want auto-enrol based on SAML)
542 sites
21 fans
Current versions available: 4


Donations are welcome to support the development of the plugin.

Moodle's SAML PluginMoodle's SAML Plugin


  • Mark Stewart - Moodle Administrator in New Zealand

Info of the plugin

This plugin add SAML authentication support to Moodle.
If you need auto-enrol based on SAML you need to install the SAML Enrolment Plugin too.


Install in the same machine a simpleSAMLphp instance and configure it as a Service Provider

Install Instruction
1. Unpack this saml directory into the /auth/ directory as you would for any Moodle auth module (

2. Login to Moodle as an administrator, and activate the module by navigating
Site administration->Plugins->Manage authentication->SAML Authentication

3. Let priivileges to the server user to write over the auth/saml/saml_config.php file.

After the installation we must configure the saml plugin, so go to "Settings" if you are in
"Manage Authentication" page, or you can also go to Users > Authentication > SAML Authentication. These are the fields of this form:

  • simpleSAMLphp Path: it will not work unless you specify the saml library path. This refers to the library path for the simpleSAMLphp environment you want to use. For example: /var/simplesamlphp/lib
  • SimpleSAMLphp SP source. Select the SP source you want to connect to moodle. (Sources are at the SP of simpleSAMLphp in /config/authsources.php).
  • SAML username mapping: it is a SAML attribute that will be mapped to the Moodle username. By default, this attribute will be set to 'mail'.
  • Single Log out: Enable/disable the single logout. This will log out you from moodle, identity provider and all conected service providers 
  • SAML Image: when you enable the SAML authentication plugin, a new button will be shown in the login Moodle page that allows to authenticate via SAML. By default, the simpleSAMLphp image (something like a fish) will be shown, but you can specify another one you want to use. Note: this image needs to exist in the server as it is not possible to upload an image through the form right now. 
  • SAML login description: you can also specify a description text for the previous button. This description will be shown below the SAML image in the login Moodle page.
  • Log file path: this is the absolute path of a file where the plugin will log information about its actions. It is optional.
  • Hook file path: this is the absolute path of a file with php functions that will be called to alter the default behaviour of this plugin. See the file custom_hook.php for more information.
  • SAML support Courses: this select has three options:
    • No suport (default value): the plugin will not have support for enrolling the user into courses automatically
    • Internal: the plugin will use an internal database table to map the courses in the next field with Moodle courses 
    • External: the plugin will use a tabla in an external database to map the courses in the next field with Moodle courses.
  • SAML courses mapping: it is a SAML attribute that is mapped to Moodle courses data. By default, it is set to 'schacUserStatus'.
  • Field used to identify a course: this can be the Short Name or the Number ID and referes to the Moodle field used to identify a course during the matching phase of the plugin.
  • Ignore inactive courses: if this field is checked the user will stay in previous enrolled courses even if the status of the course is inactive in the SAML attribute. 
  • Data Mapping section:  The Identity Provider (IdP) provides some user's data such as the first name, surname, email address, etc. In this section, you can specify the correspondence with the same data in Moodle. By default, the configuration is set as is shown below: First name = cn Surname = sn Email Address = mail
  • Course Mapping section: The course mapping section allows the administrator to link saml courses and moodle courses. To make it working we need to create an intermediate database on where we can store this data. This database will have the following internal structure:
    Field Type  Null   Key  Default    Extra
    course_mapping_id int(11)   NO   PRI   NULL  auto_increment
    saml_course_id    varchar(20)  NO    NULL  
     saml_course_period  int(4)  NO    NULL  
     lms_course_id  text  NO    NULL  

    Once we already have created the database, we need to specify the DSN (Data Source Name) that has the following syntax: 
    • MySQL
    • SQLite
    • PostgresSQL
  • Below the database DSN field we can start introducing course mappings between Moodle and SAML courses. No field can be null, if you try to introduce a null course mapping, this data will be ignored and it will not be saved in the database. If you try to introduce a duplicate course mapping this data will not be saved in the database and you will be redirected to the form showing an error. If you want to delete a course mapping you must only check the corresponding checkbox to the left and clicking to 'delete' button. Also, you can update the previous introduced course mappings in every moment if the new data doesn't conflicts with none of the previous course mappings. Is possible to introduce several course mappings at the same time, you can add a new row by clicking in '+' button to the right. It no errors happen while introducing the course mappings, you will be redirected to the 'Manage Authentication' page as with any other field of the form.
In order to support course enrolling you must install the SAML Enrolment plugin, otherwise set SAML support Courses to 'no support'. 

Internal Changes
The 'config.html' file was renamed to 'config.php' because it now has PHP code. - Two new files was created in SAML plugin directory: - 'courses.php': this file contains the needed PHP code for showing the new 'Course mapping' table. - 'DBNewDatabase.php': this file contains a tiny function for creating a database connection, because it seems there is a bug when you try to open a SQLite database connection using a DSN.

In 'auth.php' we have used 'validate_form' for validating the form and store the errors, and 'process_config' for saving the data into the database if there are no errors. Also, 'sync_roles' function have been modified for mapping roles and courses.

These changes are tested and valid for simpleSAMLphp >= 1.7

Important for enrollment!!

This plugin suppose that the IdP send the courses data of the user in a attribute that can be configured but the pattern of the expected data is always

You can change this pattern editing the file auth/saml/course_mapping.php

Default pattern is:  <country> : <domain> : <courseId> : <period> : <role> : <status>
status could be 'active' or 'inactive',
courseId, period and role depends on the configuration of the mapping.

And you may prefix it with the urn of your attribute. The default vaulue for carry course data is shacUserStatus so you may prefix the prevous string with the related urn

If you use other attribute than shacUserStatus or you want to change the fortmat of the course data you may edit the course_mapping.php file



Problems with the login view

SAML auth plugin rewirte the login view I had to copy some code of the login/index.php view and made some changes. If you find problems on the login view, you can disable the "login view replacement". Edit the auth/saml/auth.php, at the the loginpage_hoook funcion, disable the following code:
        if (empty($CFG->alternateloginurl)) {
            $CFG->alternateloginurl = $CFG->wwwroot.'/auth/saml/login.php';

Then edit the login/index_form.html and insert before:


<h2><?php print_string("returningtosite") ?></h2> 


the following code

Who is using SAML plugin?


Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3


Picture of Sixto Martin Garcia
Sixto Martin Garcia (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS


  • Picture of Paul Martin
    Fri, Dec 2, 2011, 2:36 AM
    It seems as though dual login capabilities have been removed from this version. Are there any plans to re-implement them? Currently, we use LDAP authentication, and without dual login, no one can login to the system.
  • Picture of Sixto Martin Garcia
    Mon, Dec 19, 2011, 9:47 AM
    Dual capabilities still works with this plugin. And also you could enable an IdP that uses your ldap as authentication source.
  • Picture of Jose Barrera
    Thu, Jan 26, 2012, 6:25 PM
    Hi Sixto,
    Is this compatible with Moodle 1.9?
  • Picture of Sixto Martin Garcia
    Fri, Jan 27, 2012, 12:44 AM
    This plugin is only compatible with 2.X versions. If you need a 1.9.X versión you must check this repository: But the 1.9.X plugins have the enrol and auth modules mixed in one.
  • Picture of Jose Barrera
    Fri, Jan 27, 2012, 5:11 PM
    Gracias Sixto por tu respuesta y por la información adicional que me enviaste.
    Un saludo cordial.
  • Picture of Kris Stokking
    Sat, Feb 11, 2012, 12:40 AM
    I've noticed that there are two SAML authentication plugins for 2.X - this version, and the version from Piers Harding (who is also the maintainer of the 1.9 version) at Was there a reason for forking the plugin? What are the main differences between the two versions? Thanks very much in advance.
  • Picture of Sixto Martin Garcia
    Fri, Feb 17, 2012, 4:03 AM
    Hi Kris Stokking,
    I don't know what are the differences between that version and Piers's version. Both implementations came from the old "Ny Media AS"s version (2008).

    This plugin is used in CONFIA, an Andalusian federation identity so I'm maintaining it. My deployments were older than Piers and when I saw he added the plugin to the moodle forge I sent him my improvements, but he didnt answered me so I kept working on my repository ( due I had a roadmap to accomplish. Later he answered me and said that he had added some of my patchs but I needed all them and my new improvements so that the reason of the "fork", I kept working and for 2.X version I rebuild and refactored all code and published here. Now Im deploying SAML plugins for others open source projects and have not time to analyze the differences and send Piers the patch with the improves.
  • Picture of James Henestofel
    Tue, Apr 3, 2012, 1:38 AM
    Hi Sixto,
    We currently have SAML setup on our internal webserver to handle all our internal systems but our Moodle is hosted externally. Is it possible to have SSO with this plugin without installing SAML on our Moodle server.
  • Picture of Sixto Martin Garcia
    Mon, Apr 9, 2012, 7:37 PM
    Hi James,
    You need to configure a SP (simplesamlphp instance) that protect your external Moodle and then install and configure the SAML Authentication plugin.
  • Picture of Shail Jai
    Tue, Apr 10, 2012, 9:18 PM
    HI Sixto , one confusion where I have to enter DSN setting in which file ? I created database by your sql file but I don't know where I should enter those setting ? (course , role mapping section)
Please login to post comments