Your Moodle version

Authentication: SAML Authentication (simpleSAMLphp required)

auth_saml
Maintained by Picture of Sixto Martin Garcia Sixto Martin Garcia
SAML Authentication plugin based on the simplesamlphp software. (Also install the SAML Enrolment plugin if you want auto-enrol based on SAML)
528
586
8
Moodle 2.0, 2.1, 2.2, 2.3, 2.4, 2.5

Donations

Donations are welcome to support the development of the plugin.

Moodle's SAML PluginMoodle's SAML Plugin

 


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.


Prerequisites

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 (http://docs.moodle.org/en/Installing_contributed_modules_or_plugins).

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.

Configuration
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
      mysql://user:password@host/database_name
    • SQLite
      sqlite:///path/to/database/file
    • PostgresSQL
      postgres://user:password@host/database_name
  • 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.

NOTES
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.
Example  es:moodle.org:00001:2009-10:student:active 

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
Example:
urn:mace:terena.org:schac:userStatus:es:moodle.org:00001:2009-10:student:active

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?

Screenshots

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

Contributors

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

Comments RSS

Show comments
  • Picture of Stephen Cohoon
    Wed, Jun 10, 2015, 12:07 AM
    Greetings Sixto,

    I recently upgraded the site to 2.9. I was running 2.8 and the SAML authentication module--though not configured, I could view the "settings" page. I am *now* setting up the SAML module on 2.9 and I am unable to access the "settings" page. I get a "page not found"-404 error.

    Does the SAML authentication module work for 2.9?
  • Picture of Jason Maddern
    Fri, Jul 17, 2015, 6:41 AM
    Hi Sixto / Jan,

    This plugin doesn't list official compatibility with moodle 2.9. Is there a release date planned for this?

    Thanks, jason
  • Picture of Sixto Martin Garcia
    Tue, Jul 21, 2015, 12:56 AM
    I deployed a new version compatible with Moodle 2.9.

    I'm also looking for some help. Donations or contributions to the code are always welcome to keep this plugin alive.
  • Picture of Javier Ayllon
    Wed, Jul 22, 2015, 8:20 PM
    Hi Sixto, I've installed the new version on a 2.9 and I see issues. Is there an official forum thread to discuss this?
  • Picture of Harald Torbjørnsen
    Tue, Aug 11, 2015, 2:21 PM
    Hi Sixto.
    We have this issue that if we have links to resources inside our Moodle site, from a extern website, the user will be send to “My home”, instead of back to the resource, after being redirected to saml login.

    Is there a way to solve this issue?
    (We are running Moodle 2.8 )
  • Picture of Sixto Martin Garcia
    Tue, Aug 11, 2015, 10:07 PM
    @Harald, I think that you are experience a session conflict problem. Do you mind to configure simpleSAMLphp to use memcache as session handler instead of your current handler (Deploy a memcache server, install the php driver for memcache, restart the web server, and at simpleSAMLphp, config/config.php set 'store.type' => 'memcache',
  • Picture of Memet Ødegaard Cataltepe
    Fri, Dec 11, 2015, 5:58 PM
    What are the plans for this plugin and Moodle 3.0? We want to integrate Feide, but need auth_saml to set it all up.
  • Picture of Javier Flaqué
    Mon, Dec 21, 2015, 7:53 PM
    Hi.

    I have this error when trying to connect . Caused by: sspmod_saml_Error : Requester / InvalidNameIDPolicy
    Do you know what can be the solution ?
    It is a connection with ADFS.

    Thank you.
    ------
    Hola.

    Me esta dando este error Caused by: sspmod_saml_Error : Requester / InvalidNameIDPolicy
    La conexión es contra un ADFS. Saben cual puede ser el error?

    Gracias.
  • Picture of Stephen Harvey
    Mon, Jan 25, 2016, 10:36 PM
    Hi,

    Has anyone tried the current version (2.9) with Moodle 3.0+ ?

    Also do we know if this plugin will be updated to work with Moodle 3:0+, if so is there a timescale?
  • Picture of Sixto Martin Garcia
    Wed, Jan 27, 2016, 1:06 AM
    Currently I'm not able to maintain properly this plugin, so a new release compatible with Moodle 3.0+ is not expected.

    Understand that I'm the unique contributor of that plugin since 2011 and maintain it take a lot of my spare time. I receive 5-10 messages per month requesting SAML support. There are at least 660 sites using this Moodle's SAML extension, but no one donated, kinda sad.

    If some php programmer/moodle guru interested, I can teach him how the plugin works and make him contributor.
  • Picture of Andreas Figge
    Thu, Feb 18, 2016, 9:01 PM
    This Plugin actually works with Moodle 3.0+ all you have to do is to add the line

    $plugin->component = 'auth_saml';

    to version.php
  • Picture of Olumuyiwa Taiwo
    Thu, Mar 3, 2016, 9:34 PM
    @Sixto, How do I become a contributor for this plugin? I've used it for a client so I have a fairly good idea how it works.
  • Picture of Sixto Martin Garcia
    Thu, Mar 3, 2016, 11:18 PM
    @Olumuyiwa There is a repository https://github.com/pitbulk/moodle_saml , you can contribute there.
  • Picture of Sam Lewis
    Fri, Apr 1, 2016, 12:42 AM
    How do I get Moodle to logout when SimpleSAMLphp receives a LogoutRequest from the IdP?
  • Picture of Simon Harbinson
    Wed, Jun 22, 2016, 10:58 PM
    Hi Can some one confirm this for me, we are running version = 2015072901, on a 3.0 Moodle I trying to get User Data mappings working. I see in the Auth.php following

    $fields = array("firstname", "lastname", "email", "phone1", "phone2",
    "department", "address", "city", "country", "description",
    "idnumber", "lang", "guid");

    I assume that these are these fields correspond to the User Data Mapping section in the SAML config in Moodle.

    I have set these but they are not working, is the function currently working. or.....

    Thanks SImon



1 2 3 4 5 6 7
Please login to post comments