Logging into Moodle via external site

2019-05-16 03:40发布

I'm setting up a Moodle environment and I need users to be able to login via an external site using their credentials from that site. Ideally they would go to the website, login in, and then click a button that will send them to Moodle along with their account information.

Once they get to Moodle, Moodle will check to see if the account information already exists. If so it will login, otherwise it will create the account and login.

I already have the Moodle environment set up, as well as the login site. The Moodle site is not allowed to access the database on the login site, and the users shouldn't have to enter their information again at any point.

I've already spent several hours attempting to work backwards from a plugin that accomplishes something similar between Moodle and social networking sites (facebook, twitter, google+, etc) but made no progress, as well as from a plugin that linked Moodle with Joomla, and I've searched through here and other forums for anything I could find similar to what I need to accomplish to no avail. Any help would be very appreciated.

Edit: I forgot to mention that the Moodle version is 2.5.4

Edit: The following will create a new user with data posted to the "login/index.php" page. This is currently very incomplete and probably dangerous to implement on a production server. Updated versions will be posted as I continue to work on it, suggestions are more than welcome.

    global $CFG, $DB;
    require_once($CFG->dirroot.'/user/profile/lib.php');
    require_once($CFG->libdir.'/authlib.php');

    $newuser = $DB->get_record('user', array('id'=>'1'));
    $newuser->auth = 'manual';
    $newuser->username = $frm->username;
    $newuser->password = hash_internal_user_password($frm->password);

    $newuser->username = $DB->insert_record('user', $newuser);

    /// Save any custom profile field information
    profile_save_data($newuser);

    $newuser = $DB->get_record('user', array('id'=>$newuser->username));
    events_trigger('user_created', $newuser);

2条回答
forever°为你锁心
2楼-- · 2019-05-16 04:21

Using external database authentication is probably the easiest to set up, especially if both systems are on the same server.

go to Site Admin > Plugins > Authentication > Manage Plugins -> Click the unhide button next to External Database

Then click on the settings and add the connection details for your database, name of the external table (or create a view if the data is from several tables) and add the field mappings.

http://docs.moodle.org/26/en/External_database_authentication

Alternatively, I would use the SimpleSAML plugin with LDAP - assuming you have an LDAP server - takes about a day to set up and mess about with the settings.

https://moodle.org/plugins/view.php?plugin=auth_saml

查看更多
相关推荐>>
3楼-- · 2019-05-16 04:34

Having a similar issue, I am thinking of an approach that

  • let the main site create an extra database with enrolment information on a daily basis. I wanted to provide that as an SqLite file, but it appears that moodle external database plugin does not support SqLite database.

  • depending on the username and the access control logic on the main site show a menu "moodle"

  • if user clicks on "moodle" do a post request to moodle login with username and a secret token between moodle and the main site.

  • implement a simple authentification plugin for moodle which asks the main site for confirmation that the user is still logged in. It will use the shared secret token for this. If main site does not confirm that user is logged in then redirect to the login page of the main site.

But I am not sure if

  • the approach really works
  • the approach is suitable
  • the approach is already implemented by someone

I investigated SSO stuff like shiboleth but it appears pretty complicated and hard to implement in particular since our main site already has an authentification approach.

查看更多
登录 后发表回答