Giter Site home page Giter Site logo

moodle-drupalservices's Introduction

moodle-drupalservices

Moodle plugin to connect to Drupal services

This is a moodle authorization plugin that allows for SSO between Drupal and Moodle. All users are maintained on Drupal and Moodle authenticates via REST to the drupal Services module.

In this project we support the current major version of Moodle and any of its minor versions. currently that is Moodle 2, and we have support for 2.4 and higher within Moodle 2.

The branch structure is as follows: [Moodle version]-[plugin version]. Development branches for this plugin are denoted with a ".x-dev" for example 2.x-dev. For users who want stable releases only, you can chose from the Tagged releases. these are denoted with a number instead of x, for example 2.x-2.01, 2.x-2.02 etc.

To chose the proper branch, decide which version of the DrupalServices plugin you wish to use. If you use any version of moodle 2 beyond 2.4, and you would like to use our 2.x development line, make sure you take code from the branch "2.x-2.x-dev". If you don't trust the stability risk of a development line, use the highest numbered tag for your moodle and plugin version. For example: 2.x-2.00

Configuration instructions have been moved to the github wiki. https://github.com/cannod/moodle-drupalservices/wiki

If you would like to help collaborate on this project, please request using a GitHub issue and we'll add you as a Collaborator.

moodle-drupalservices's People

Contributors

netw3rker avatar ocitguy avatar pchec avatar zigmazigmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moodle-drupalservices's Issues

Module breaks with new Drupal Services update?

I upgraded my Drupal Services module to the latest version because it has security updates. After doing so, authentication breaks on Moodle. I downgraded Services to the previous version without doing anything else, and it worked again. I haven't nailed down the actual issue, but here are some clues:

  1. When running the sync_users script from command line the updates all complete successfully but I get a HTTP 401 error on attempting to log out.
  2. Earlier it was sending me back to my Drupal login (as it should) with some kind of Moodle error code 2 in the query string. I can't remember the exact query string text, but I can't seem to reproduce it either.

Anyone have any ideas about what could be wrong?

User login unstable (problem getting index of users / timeout)

First of all thank you for the great work on this module.
I really like the concept of using services.
On my local and test machines I got everything working, however the module proves too unstable to use it in production.

I'm getting the following error on the config page:
muser/Index: User session data reachable but you aren't logged in! Check that the access permissions are correct in the muser view's service display
And using the CLI script:
ERROR: Problems trying to get index of users!

This sounds strange because I also get:
Success : system/connect: User session data reachable and you are logged in!

So I added the following to the file auth.php (at the end of test 3):

    else {
        $tests['auth']=array('success'=>false, 'message'=> "user/login: Login to drupal failed with http code " . $ret->info['http_code']);
            if (!empty($ret->error)) {
              $tests['auth']['message'] .= PHP_EOL . $ret->error;
            }
          }

This gives me extra info:
Fail : user/login: Login to drupal failed with http code 0 Operation timed out after 4003 milliseconds with 0 bytes received

So there is a timeout during login (using the POST method via curl to the service view).
This is strange since the other POSTs don't timeout, and the muser view is accessible (by the remote user and authenticated users).

Any ideas?

CiviCRM + Drupal + Moodle

Hi all,
This is a great module.
So far it works quite good.
What I'm curious is - is it possible to use CiviCRM fields instead of creating those fields in Drupal?
CiviCRM (a Drupal module) contains all needed fields: firstname, lastname,city, country etc.
How can I send that to Moodle?
Moodle + Drupal is a great combination. If we can add CiviCRM to that mix, that would be a solution for almost anything we need (a dream come true:).
Please advise,
Vjeko

Plugin not enabled

Hello,

I've finally worked through the other issue I was having and the cron job appears to be trying to work, but I get the response that the plugin is not enabled. I have checked moodle and even disabled and re-enabled the plugin to make sure.

Here's the exact error:
X-Powered-By: PHP/5.3.25
Content-type: text/html

Plugin not enabled!

I'm using drupal 7.22 and Moodle 2.4.1

Thank-you

New users not being created immediately

Is there any way to create a new user in Moodle immediately when a user is created in Drupal, rather than waiting for the sync script to run? In my case, users create their own accounts, and they generally do so when they are ready to take a course. With the current set up, I would have to do something like run the cron job once per second, which obviously isn't going to work. I am trying to write a module using hook_user_update, but I don't have enough skill to make this work. It seems like this would be the most common way that people would want to use this, but maybe I'm wrong.

User doesn't log out from Drupal when Moodle Logout happens

Problem

In 2.x-2.x, when user logs out from moodle, he doesn't log out from drupal although the relate option is set.

Supposed motivation

I've found a bug in the code, in auth.php line 233

function logoutpage_hook()
{
    [...]
    if ($drupalsession=$this->get_drupal_session() ) {
        if (get_config('call_logout_service', 'auth_drupalservices')) {
        [...]

the get_config params are written in inverted order (moodle 2.8), so it always skips the condition.

Drupal Services Settings Page Broken

Hello there,

I am trying to install Drupal Services plugin in Moodle. I followed the documentation and have configured my Drupal instance and now trying to set it up in Moodle but when I deploy the plugin I do not see settings page as it's mentioned in the Manual. I mean I only get one option i.e. configure Drupal Website URL which I have specified but I do not see other options like service auth user/pass, field mappings etc.

Moodle is installed at http://labs14.xyz.com/MoodleSSO
Drupal is installed at http://labs14.xyz.com/DrupalSSO

Please see below image for reference. Thank you.
image

Fail : muser/Index: The muser resource is not available in the drupal service endpoint

Hello.

I tried to follow the installation instructions on the wiki, drupal side and moddle side (drupal and moodle modules up to date) on a local apache server, and got the "Fail : muser/Index: The muser resource is not available in the drupal service endpoint" error after hours of debugging.....

The messages are the followings :

Success : cookies: SSO Cookie discovered properly
Success : system/connect: User session data reachable and you are logged in!
Success : user/login: Logged in to drupal!
Fail : muser/Index: The muser resource is not available in the drupal service endpoint.

And my "Services" export (checked all of the ressources to avoid errors/problems) :

$endpoint = new stdClass();
$endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */
$endpoint->api_version = 3;
$endpoint->name = 'moodlesso';
$endpoint->server = 'rest_server';
$endpoint->path = 'moodlesso';
$endpoint->authentication = array(
'services' => 'services',
);
$endpoint->server_settings = array(
'formatters' => array(
'json' => TRUE,
'xml' => TRUE,
'bencode' => FALSE,
'jsonp' => FALSE,
'php' => FALSE,
),
'parsers' => array(
'application/json' => TRUE,
'application/x-www-form-urlencoded' => TRUE,
'text/xml' => TRUE,
'application/vnd.php.serialized' => FALSE,
'application/xml' => FALSE,
'multipart/form-data' => FALSE,
),
);
$endpoint->resources = array(
'comment' => array(
'operations' => array(
'create' => array(
'enabled' => '1',
),
'retrieve' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
'delete' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'countAll' => array(
'enabled' => '1',
),
'countNew' => array(
'enabled' => '1',
),
),
),
'file' => array(
'operations' => array(
'create' => array(
'enabled' => '1',
),
'retrieve' => array(
'enabled' => '1',
),
'delete' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'create_raw' => array(
'enabled' => '1',
),
),
),
'moodlesso' => array(
'operations' => array(
'index' => array(
'enabled' => '1',
),
),
),
'node' => array(
'operations' => array(
'retrieve' => array(
'enabled' => '1',
),
'create' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
'delete' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'relationships' => array(
'files' => array(
'enabled' => '1',
),
'comments' => array(
'enabled' => '1',
),
),
'targeted_actions' => array(
'attach_file' => array(
'enabled' => '1',
),
),
),
'system' => array(
'actions' => array(
'connect' => array(
'enabled' => '1',
),
'get_variable' => array(
'enabled' => '1',
),
'set_variable' => array(
'enabled' => '1',
),
'del_variable' => array(
'enabled' => '1',
),
),
),
'taxonomy_term' => array(
'operations' => array(
'retrieve' => array(
'enabled' => '1',
),
'create' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
'delete' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'selectNodes' => array(
'enabled' => '1',
),
),
),
'taxonomy_vocabulary' => array(
'operations' => array(
'retrieve' => array(
'enabled' => '1',
),
'create' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
'delete' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'getTree' => array(
'enabled' => '1',
),
),
),
'user' => array(
'operations' => array(
'retrieve' => array(
'enabled' => '1',
),
'create' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
'delete' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'login' => array(
'enabled' => '1',
),
'logout' => array(
'enabled' => '1',
),
'token' => array(
'enabled' => '1',
),
'request_new_password' => array(
'enabled' => '1',
),
'register' => array(
'enabled' => '1',
),
),
'targeted_actions' => array(
'cancel' => array(
'enabled' => '1',
),
'password_reset' => array(
'enabled' => '1',
),
'resend_welcome_email' => array(
'enabled' => '1',
),
),
),
);
$endpoint->debug = 0;

HELP please !!

When Moodle Drupal Integration i have faced this issue i couldnt figure out

The following messages are the results of tests of the configuration below. Use these to guide you through the setup and configuration of the Drupal Services plugin. If you see any items with 'fail', you'll need to resolve them in order for this plugin to work.
Fail : cookies: SSO Cookie not discovered. 1) check that you are currently logged in to drupal. 2) Check that Drupal's session cookie is configured in settings.php 3) check that cookie_domain is properly filled in.
Fail : system/connect: User session data reachable but you aren't logged in!
Success : user/login: Logged in to drupal!
Success : muser/Index: User listings are active!

ERROR: Login error!

Ok, so up to the point of testing the script in cmd everything works.

On Moodle side I have:
Hostname: http://www.mydomain.com
Endpoint: /drupalservice
Remote User: moodle remote username (not the name actually in use)
Remote user password: is correct

I have sudo permissions on the account I am logging into putty with. I then cd to the drupalservices directory and enter the following command: sudo /usr/bin/php auth_drupalservices_sync_users.php then it waits a moment and gives the login error.

I've tried:
sudo /usr/bin/php /public_html/moodle/auth/drupalservices/auth_drupalservices_sync_users.php ...got 404 error

sudo -u moodle remote username /usr/bin/php auth_drupalservices_sync_users.php ...user does not exist ...(Replaced moodle remote username with actual username)

sudo -u www-data /usr/bin/php auth_drupalservices_sync_users.php ...user does not exist

Thank-you for your help

Regular drupal users cannot login at moodle side.

I have been able to get my drupal admin account to login and successfully cross over to moodle and also login there. Perfect. But I started with some test user and it won't work. Looks like the user object is empty, like the service isn't working for normal authenticated drupal users accounts? So odd I can get my Drupal admin to work, but no others.

My drupal admin and moodle admin DO NOT share the same username or email address, they are clearly different. Thanks for ideas, I keep looking...

Error log from PHP:

line 89 of \login\index.php: call to auth_plugin_drupalservices->loginpage_hook()

[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 156
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 157
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 158
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 160
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 162
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 163
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 164
[09-Sep-2014 19:19:23 America/New_York] PHP Notice: Trying to get property of non-object in E:\Inetpub\wwwroot\bhrp_commerce_kickstart\bhrplms\auth\drupalservices\auth.php on line 165
[09-Sep-2014 19:19:23 America/New_York] Default exception handler: Error writing to database Debug: Column 'username' cannot be null
INSERT INTO mdl_user (username,firstname,lastname,auth,mnethostid,lang,confirmed,email,idnumber,city,country) VALUES(?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => NULL,
1 => NULL,
2 => NULL,
3 => 'drupalservices',
4 => '1',
5 => 'en_us',
6 => 1,
7 => NULL,
8 => NULL,
9 => NULL,
10 => NULL,
)]
Error code: dmlwriteexception

  • line 446 of \lib\dml\moodle_database.php: dml_write_exception thrown
  • line 1080 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1122 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 189 of \auth\drupalservices\auth.php: call to mysqli_native_moodle_database->insert_record()
  • line 127 of \auth\drupalservices\auth.php: call to auth_plugin_drupalservices->create_update_user()
  • line 89 of \login\index.php: call to auth_plugin_drupalservices->loginpage_hook()

Need updated documentation

The plugin is evolving quickly, and documentation is getting progressively further out of date. In order to hit our 1.0 milestone, we should have proper documentation available.
This issue should be used to cross reference issues that also require documentation corrections or additions.

sync script

A "sync script" is referenced in both the wiki and the moodle drupal services page after you install the plugin, but I don't see it anywhere in the code base? Am I missing something?

Users synchronization fails

Hi everyone,

I'm trying to set up this plugin following the instructions on the wiki.

It works all properly until the users synchronization shell. It seems to retrieve users from Drupal (there is the number of user entries to update) but then it keeps saying: "Error writing to database!".

I also gave the moodle user database the correct permissions to the drupal database (select and delete) as I read it somewhere in these forums before.

I don't understand what I'm doing wrong. Is there someone that can help me?

Thank you very much.

It all seems to install correctly, but nothing seems to be working.

Hi, I've been struggling to actually get this up and running. I seem to be able to install everything correctly, but on the Moodle configuration for the plugin I never get to see any error or success messages, I just save the config and that's it. I'm not sure if that just means it's all good.

I'm using:

  • Moodle 2.7.3
  • Drupal Services plugin from the 2.x-2.x-dev branch (downloaded 23/12/2014)
  • Drupal 7

And I've followed all the instructions here:
https://github.com/cannod/moodle-drupalservices/wiki

My sites are on these addresses:

Drupal: http://dev.example.org
Moodle: http://study.example.org

And I've set up the cookie on both settings.php files in the Moodle auth plugin and the Drupal site to be '.example.org'

If I log in to Drupal I am not logged in to Moodle, and if I log out of Moodle it doesn't log me out of Drupal, it also doesn't create any new accounts in Moodle for users registered through Drupal, so I don't think it's actually working at all. If I'm not logged in to Moodle and try to access a restricted Moodle page, it will send me to the Drupal site though, with an access denied message, so there's one thing that seems to be happening.

Also, if I turn debugging on in Moodle I can see that it does connect and it does give me the correct details for the logged in user if I'm logged in over on Drupal, so I'm guessing something is working here as well.

I'm not sure what else I can check as I've been fiddling with the settings for days and still haven't got any further than this.

I've attached a screenshot of my Moodle configuration.

Here's an example of what the Moodle debugging gives me for a logged in user. (replaced actual usernames with 'user')

Service were reached, here's the logged in user:stdClass Object
(
    [sessid] => AhPVXIm9CxwQG72G382T7PIypjPyK53u-mGUeXprUs8
    [session_name] => SESS0b12d37693d4b67a977bd91cd8ec81d5
    [user] => stdClass Object
        (
            [uid] => 142
            [name] => user
            [mail] => [email protected]
            [theme] => 
            [signature] => 
            [signature_format] => tinymce
            [created] => 1419300429
            [access] => 1419384452
            [login] => 1419382773
            [status] => 1
            [timezone] => Asia/Bangkok
            [language] => 
            [picture] => 0
            [init] => [email protected]
            [data] => stdClass Object
                (
                    [contact] => 0
                    [overlay] => 1
                )

            [vid] => 146
            [ip] => 122.148.1.1
            [sid] => AhPVXIm9CxwQG72G382T7PIypjPyK53u-mGUeXprUs8
            [ssid] => 
            [hostname] => 182.160.1.1
            [timestamp] => 1419384452
            [cache] => 0
            [session] => 
            [roles] => stdClass Object
                (
                    [2] => authenticated user
                    [3] => administrator
                )

        )

)

moodlesettings

Cohorts?

Thank you so much for writing this awesome module. I am interested in the 'cohort' options that you currently do not advise using at this stage. I am interested in helping you get that feature up and running. Do you have a starting point?

Cross Domain SSO

This module needs to support actual cross domain SSO. To clarify, this assumes that the master user record (drupal) is on domain "drupalexample.com" and moodle is running on "otherexample.com". This is currently not possible and should somehow be.

The two main questions I have are:

  1. should this be handled by moodleservices, or simply integrated with another plugin that already supports cross domain sso
  2. are there best practice approaches to accomplish this. If there are any standards or best practices, lets bring them up here.

I'd also like to evaluate the need for this. Do we have any users that are currently looking for or waiting for this functionality? If so, weighing in is important, and also volunteers for testing are very important.

keep in mind that this is different from cross subdomain sso, which is currently supported in the 1.x version of this module (across all supported versions of moodle). This means that if the master user record (drupal) is on domain "drupal.example.com" and moodle is on "moodle.example.com". SSO currently does work.

I've added this as a 2.0 milestone, so we've got a lot of time to work this out. lets get to discussing!

Wiki Documentation

I just edited the Wiki page to include these missing requirements on the Drupal install side:

Chaos tool suite (ctools)
User Revision

Logging out of Moodle or Drupal does not log out the other one.

Using the 2.x-2.x-fix_url_redirect branch, I'm having an issue where logging out of Moodle will not log out the user on the Drupal site, this results in Moodle doing what it does by default, logging out the user and sending them to the home page of Moodle, but because they are still logged in on Drupal it logs them back in to Moodle, so the user gets stuck in a loop where they hit logout, the page refreshes a couple of times and then they are still logged in.

Also logging out of Drupal doesn't log out the user on Moodle, so this means that if I'm using the Drupal site as the main log in and log out portal, if there are multiple users on one computer, one user will log out on Drupal, but wouldn't get logged out in Moodle, then the next user would log in to Drupal, go to Moodle, but still be logged in as the previous user in Moodle.

I was going to just put in my own workarounds around this, but if the plugin can do it more elegantly, that'd be great.

I was going to edit the section of code in Moodle's /login/logout.php file line 35-40:

// can be overridden by auth plugins
if ($login) {
    $redirect = get_login_url();
} else {
    $redirect = $CFG->wwwroot.'/';
}

To something like this so that it would go straight to the Drupal logout once the user is logged out in Moodle:

// can be overridden by auth plugins
if ($login) {
    $redirect = get_login_url();
} else {
    $redirect = 'http://dev.example.com/user/logout';
}

But by the looks of the comment there, the auth plugin should be able to do this without me needing to hardcode it in.

Cannot connect to Drupal...

I have been struggling to configure the Drupal Services module in Moodle for several days now. I am using

  • Moodle 2.6
  • Drupal Services plugin from the 2.x-2.x-dev branch (downloaded 19/12/2014)
  • Drupal 7

Both Moodle and Drupal are installed on my localhost, and I have set up a domain locally on my computer, i.e. they are located at:

  • sso_test.com/moodle_sso
  • sso_test.com/drupal_sso

I have followed the configuration instructions for both Drupal and Moodle as outlined at:

https://github.com/cannod/moodle-drupalservices/wiki

In the Drupal Services configuration page, I have set the Drupal Website URL to:

http://sso_test.com/drupal_sso

Nevertheless, I am experiencing problems connecting to the Drupal installation. Users who are defined in the Drupal database cannot log into Moodle.

With Moodle debugging turned on, I see the following information at the top of the Drupal Services configuration screen:

Using preconfigured values: stdClass Object ( [call_logout_service] => 0 [cohorts] => 0 [cohort_view] => [field_map_address] => 0 [field_map_city] => 0 [field_map_country] => 0 [field_map_department] => 0 [field_map_description] => 0 [field_map_email] => 0 [field_map_firstname] => 0 [field_map_idnumber] => 0 [field_map_institution] => 0 [field_map_lang] => 0 [field_map_lastname] => 0 [field_map_phone1] => 0 [field_map_phone2] => [field_map_url] => 0 [host_uri] => http://sso_test.com/drupal_sso [remote_pw] => moodle-user [remote_user] => moodle-user [version] => 2014111400 )

line 79 of \auth\drupalservices\settings.php: call to debugging()
line 85 of \lib\classes\plugininfo\auth.php: call to include()
line 95 of \admin\settings\plugins.php: call to core\plugininfo\auth->load_settings()
line 6412 of \lib\adminlib.php: call to require()
line 19 of \admin\settings.php: call to admin_get_root()

attempting to reach service url: http://sso_test.com/drupal_sso/moodlesso/moodlesso

line 183 of \auth\drupalservices\REST-API.php: call to debugging()
line 296 of \auth\drupalservices\REST-API.php: call to RemoteAPI->CurlHttpRequest()
line 106 of \auth\drupalservices\settings.php: call to RemoteAPI->Settings()
line 85 of \lib\classes\plugininfo\auth.php: call to include()
line 95 of \admin\settings\plugins.php: call to core\plugininfo\auth->load_settings()
line 6412 of \lib\adminlib.php: call to require()
line 19 of \admin\settings.php: call to admin_get_root()

Reached out for the cookie form the server and got: stdClass Object ( [cookie_domain] => .sso_test.com [role] => Array ( ) )

line 107 of \auth\drupalservices\settings.php: call to debugging()
line 85 of \lib\classes\plugininfo\auth.php: call to include()
line 95 of \admin\settings\plugins.php: call to core\plugininfo\auth->load_settings()
line 6412 of \lib\adminlib.php: call to require()
line 19 of \admin\settings.php: call to admin_get_root()

(A screenshot of the Configure Drupal Services page is attached)

Can you advise me on what I am doing incorrectly?

drupalservicesconfigpage

Support request

Hello,

I am trying to integrate drupal 7 with moodle 2.3.1. I am following the step by step read me file.
More specific:

Drupal
I created a service moodle and endpoint name mservice and enabled the resources required. I created role services and gave it unlimited index queries permission. Created a user (moodleuser) and included him in services role.

Moodle
drupal hostname: http://localohost/drupal
endpoint: /localhost/drupal/mservice
remoteuser: moodleuser
password: moodleuser_pass

ID Number: Locked

I get no errors and tested the end point URL and it works. Though when i log in to drupal, i' m going to Moodle and i'm not logged in there. What am i missing?

Thank you in advance

Drupal logout doesn't logout Moodle

I've followed the documentation and gotten the SSO to work (which is awesome). The only trouble I'm having is that when a user logs out of Drupal, they are not logged out of Moodle (the opposite direction works though). I did a couple searches and it seems like it should work but it's not for me.

Cannot connect drupal with Moodle

Dear Jedi Developers,

I am trying to connect drupal 7 with moodle 2.8, I've followed the instructions but, I can't make drupal to connect with moodle, I get these logging lines:

loaded saved session settings config:Array
(
[host] => http://myserver/drupalTest
[cookie domain] => myserver
)
line 548 of /auth/drupalservices/auth.php: call to debugging()
line 73 of /auth/drupalservices/auth.php: call to auth_plugin_drupalservices->get_drupal_session()
line 89 of /login/index.php: call to auth_plugin_drupalservices->loginpage_hook()
attempting to reach service url: http://myserver/drupalTest/moodlesso/user/token
line 183 of /auth/drupalservices/REST-API.php: call to debugging()
line 68 of /auth/drupalservices/REST-API.php: call to RemoteAPI->CurlHttpRequest()
line 207 of /auth/drupalservices/REST-API.php: call to RemoteAPI->GetCSRFToken()
line 99 of /auth/drupalservices/auth.php: call to RemoteAPI->Connect()
line 89 of /login/index.php: call to auth_plugin_drupalservices->loginpage_hook()
attempting to reach service url: http://myserver/drupalTest/moodlesso/system/connect
line 183 of /auth/drupalservices/REST-API.php: call to debugging()
line 211 of /auth/drupalservices/REST-API.php: call to RemoteAPI->CurlHttpRequest()
line 99 of /auth/drupalservices/auth.php: call to RemoteAPI->Connect()
line 89 of /login/index.php: call to auth_plugin_drupalservices->loginpage_hook()

I think the force is not with me on this one any help is appreciated.

Create user upon first login via Drupal

In auth.php - lines 125-128 as of 3/7/2014

    if (empty($user)) {
      // User not in Moodle database yet.
      return;
    }

Not gonna work for us, as we won't be constantly synchronizing but people need to be able to sign up via drupal and get course access before a cron sync event. Suggested first draft, quick and dirty, of adding the user as needed

Change this to

    if (empty($user)) {
     $newuser = $this->get_single_drupal_user($ret->user->uid);
      $this->create_update_user($newuser[0]);
      $user = get_complete_user_data('idnumber', $uid);
    }

and add function to the class (has redundancies so the overall class could use some refactoring):

function get_single_drupal_user($drupaluid) {
    global $CFG;
    $remote_user = $this->config->remote_user;
    $remote_pw = $this->config->remote_pw;
    $base_url = $this->config->hostname;
    $endpoint = $this->config->endpoint;
    $apiObj = new RemoteAPI($base_url, $endpoint);
    $ret = $apiObj->Login($remote_user, $remote_pw);
    if (is_null($ret)) {
        die("ERROR: Login error!\n");
    }
    $drupal_user = $apiObj->Index('muser?uid='.$drupaluid);
    if (is_null($drupal_user) || empty($drupal_user)) {
        die("ERROR: Problems trying to get new user!\n");
    }
    return $drupal_user;
}

There is a bug in this approach, at this point - logging out the very first time logs you out of moodle but not out of drupal. Subsequent logins and logouts work normally.

Thoughts on the future

Here is what I have been thinking about for this plugin...

I have had a look at the Joomdle code which connects Joomla with Moodle. They have created a whole bunch of custom Moodle web services functions so that Joomla can perform remote actions like create users, courses etc in Moodle.

Joomdle also provides a Moodle auth plugin that authenticates Moodle users with Joomla.

I started coding something similar for Drupal but it starting getting a bit messy.

If anyone is interested, should we create something like Joomdle but for Drupal?

  1. Create custom Moodle web service functions. - Done.
  2. User authentication using moodle-drupalservices auth plugin but instead of services module try RESTful Web Services module - https://drupal.org/project/restws as this module will be in Drupal 8 core.
  3. On drupal side either hard code specific actions like when adding a user, call the Moodle web service function to also create a Moodle user, or plugin to rules so that we leave it to sys admins to create rules that fire off a Moodle web service function.
    I think the rules approach would give the most flexibility.

For example you could have a rule that gets run on checkout completion that enrolls a user into the purchased course all using Moodle web service functions.

I can post my code if anyone interested.

Release 1.0 needs fewer moving parts

Right now, the configuration steps are both out of date, and allow for too many configuration mistakes by users. We should provide a Drupal 'Feature' (or set of features) with all of the configuration requirements already made.(see #14 provide a feature for drupal) This, coupled with #2 (plugin needs connection tests) should allow for a much more streamlined installation process.

Todo items:

  1. Create the Features and place them in a drupal_modules folder. (should we instead create a corresponding Drupal project for these?)
  2. Update documentation to remove all of the step by step configuration options, and instead state which feature to enable.

moodle-drupalservices-2.x-2.x-dev /auth/drupalservices/ install starts but stalls until server timeout

Preface:
clean install on a localhost, using M2.6.
setup has /moodle/ as subdirectory of the drupal root

This could be a server problem, will try again, look for clues. Trouble is I put the /auth/drupalservices/ in place and goto the notifications page, moodle reports it is going to install the plugin. I proceed and goes for a long time, times out.

I understand this version will try to configure automatically:

"The 2.x-2.x version of Drupal Services will automatically try to reach your Drupal site and configure the plugin for it. If the Drupal site can't be automatically detected, you'll be prompted for a single field:"

But I wonder if it is hung up looking for the service? I had moodle debugging on put went straight to server error.


HTTP Error 500.0 - Internal Server Error
C:\php-5.4.27\php-cgi.exe - The FastCGI process exceeded configured request timeout
Detailed Error Information
Module FastCgiModule
Notification ExecuteRequestHandler
Handler php-5.4.27
Error Code 0x80070102
Requested URL http://localhost:80/bhrplms/admin/index.php?confirmplugincheck=1&cache=0
Physical Path C:\inetpub\wwwroot\drupal-moodle\bhrplms\admin\index.php


Update (different issue looks like, but documenting it anyways) :
After the 500 error, I just hit reload and get this PHP error:

Parse error: syntax error, unexpected '=', expecting ')' in C:\inetpub\wwwroot\drupal-moodle\bhrplms\auth\drupalservices\auth.php on line 178 (which is):

if (!empty($drupalfield = $this->config->{"field_map_$field"})) {

I think this empty() here may be trying to evaluate something my PHP5.4 won't do
(expressions) :

"Note:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

Version Description
5.5.0
empty() now supports expressions, rather than only variables.
5.4.0
Checking non-numeric offsets of strings returns TRUE.

Using a non standard Port

Spent quite a bit of time trying to figure out why I could sync users but not log in successfully.

I am accessing my local host on port 8080 - http://localhost:8080.

For anyone else doing development on WAMP under a non standard port like I was you will need to modify the function get_drupal_session in auth.php to remove the port number from the base url.

In Drupal I had to manually configure the cookie domain in settings.php.

In auth.php I added this line to the function get_drupal_session to strip the port immediately following this line:

list($protocol, $session_name) = explode('://', $base_url, 2);

list($session_name, $port) = explode(':', $session_name, 2);

Hope that helps someone else.

Guest Access

I can't get this to work with Guest Access on the Moodle side.

I have a Moodle course that requires guest access but, without a valid Drupal session, users get kicked back to the login page.

Is there a config value I screwed up? Is it even possible to allow guests access to courses if we are using this plugin?

We need a branch / release structure for this project

How does this sound:

moodle currently supports the following lines:

2.6.x - active
2.5.x - active
2.4.x - security only

This plugin has a solid stable build currently, but needs some features that will require some api changes, so we'll call that v1 and v2.

This will make for some long version numbers, but if we keep things inline with the d.o naming convention as well, we would have the following branches:

2.4.x-1.x-dev
2.4.x-2.x-dev
2.5.x-1.x-dev
2.5.x-2.x-dev
2.6.x-1.x-dev
2.6.x-2.x-dev

within those, we can tag releases as we see fit eg:
2.6.x-1.1
2.6.x-1.2
2.4.x-1.0-final

we can always commit to master and merge to the dev branches as we have time. This will also ensure that uses pulling the plugin will not pull down code that breaks their site unless they deliberately pull down an update that is a version higher.

Thoughts?

The moodle-drupalservices plugin does not allow users to sign in and settings to be changed.

Hi all,

Suddenly this plugin is giving me problems. I tried looking for a solution but find myself stuck.

Problem: The plugin does not allow drupal users to sign in on Moodle: the name and password are not accepted and no new user is created in Moodle. The drupalservices settings-page only displays the Drupal webpage url. The rest of the page is white.

Drupal version 7.35
Moodle version 2.8.5+ (Build: 20150313)

Drupal and Moodle are both installed in their own subdirectory. The traffic is redirected to mydomain.com for Drupal and academy.mydomain.com for Moodle. It has worked like this correctly since before the sso login problems began.

Drupal side
Moodle SSO module installed (7.x-1.x-dev)

Moodle side:
Drupalservices plugin installed: the current master version (2.x - alpha) (2014123000)

In the /sites/default folder I have changed settings.php so that the relevant line is uncommented and now shows:
$cookie_domain = '.mydomain.com';

In Moodle under administration>server>session handling I tried changing the empty field of 'cookie domain' to ".mydomain.com" but that did not resolve anything so I've deleted that entry again.

With an earlier test setup (slightly older version of Drupal core and Moodle) I had this SSO solution working nicely. I then started updating and working on other functionalities within Drupal: multi-lingual, coupons, etc. I don't know what got changed but suddenly I noticed I could not get into Moodle anymore coming from Drupal. Luckily I did not define an alternative logon url within Moodle so I can still log in with my initial manual admin account.

At the moment I notice a few things:
(1) the sso plugin on the Moodle side lets me only define a Drupal URL, nothing else. The rest of the settings I could previously see are all gone. It's just white space.

(2) Running cron on Moodle shows me the following error:
Running cron for auth/drupalservices...
ERROR: Problems trying to get index of users!

(3) Going to mydomain.com/moodlesso/ gives the result:
Services Endpoint "moodlesso" has been setup successfully.

(4) When I run cron on Moodle I see the following lines show up in the Drupal Recent Hits report:
03/17/2015 - 15:34 Services endpoint moodlesso/user Anonymous (not verified) details
03/17/2015 - 15:34 Services endpoint moodlesso/user/token Anonymous (not verified) details
03/17/2015 - 15:34 Services endpoint moodlesso/user/login *1 details
03/17/2015 - 15:34 Services endpoint moodlesso/user/token Anonymous (not verified) details

In Drupal this admin-account also has the service-authentication role appointed.

(4) When I go directly to academy.mydomain/auth/drupalservices/settings.php I am presented with an error:

Warning: require_once(/authlib.php): failed to open stream: No such file or directory in /public_html/academy/auth/drupalservices/settings.php on line 22

Fatal error: require_once(): Failed opening required '/authlib.php' (include_path='.:/usr/local/php53/lib:/usr/lib/php:/usr/local/lib/php') in public_html/academy/auth/drupalservices/settings.php on line 22

When I go to academy.mydomain/auth/drupalservices/version.php I get a white page.

At the moment SSO does not seem to work at all but I am not sure how to isolate the problem, let alone fix it. Maybe I am even asking for the obvious. Does anyone have any suggestions? Please understand I am new at this and not proficient in writing code. Thank you very much in advance.

Release 1.0 needs better user syncing

Currently the User Sync script refreshes the entire user base every time it runs. For small numbers of users, this happens fast, and isn't a problem during a high frequency Cron runs. For large numbers of users however, this is a real problem since 10k + users can't refresh inside of a high frequency run - nor should they.

Ideally the sync script should take in only additions and updates (users in drupal should never be deleted). The view should be the provider of the updates, but the script should have a method for keeping track of the last updated record so that a point in time can be requested and utilized if desired.

My suggestion:

issue: Drupal doesn't store a 'last updated' value for users. nor does it revision them out of the box. This makes incremental updates impossible.

solution: provide a generic 'change_id' value that is passed to the service resource that can optionally be used to filter for anything greater than the id passed into it. This can be generically used. If an admin only cares about new users, the UID field could be added to the service view and named 'change_id', then the filter for UID could be added that uses that variable, also being named 'change_id'.

If the admin cares about user updates, the user_revisions module provides revisioning of users (enabled by default) and with each VID establishes a time point that can be filtered upon. the User: VID field could be added to the service view and named 'change_id', then the filter for User: VID could be added that uses that variable also being named 'change_id'.

Code change in the drupalservices moodle plugin:

  1. create a variable that can be persistently stored which will track the last successful 'change_id' value.
  2. pass that value to the muser/index service resource in the form ?change_id=[change_id]
  3. take the highest change_id that is successfully imported from the set of users returned and store it in the change_id variable.

I've taken a first stab at this within the issue_23-sync_script_pagination branch I recently pushed. I'd like to see this tested w/in the next 5 or so days before putting it into 2.6.x-1.x. It should be an impact free change for existing users. So I'll need to know 2 things from this:

  1. does it work as intended
  2. does it not break existing installs that do not want this functionality

lemme know!

Create logout webservice endpoint

The Moodle SSO module for drupal provides the option to log users out of moodle when they log out of drupal, but this only deletes the shared moodle cookie. There should be an option for calling the moodle logout webservice.

This plugin should provide a preconfigured endpoint for the module to call, so that users can be properly logged out of moodle.

Mapping user fields from moodle to drupal table(s)

Hi, not really an issue, more of support request - sorry. Do you know if you can use a MySQL view table to match the user fields (first, last, city etc.)? Does everything you try to match to, need to be in one table?

Infinite loop trying to authenticate

I setup the drupalservices module according to the Wiki but I am getting an infinite re-direct loop between moodle and drupal when I sign in.

If I go to the moodle URL before signing in to Drupal it correctly re-directs me to the Drupal user logon screen.

Once I log in with Drupal it sends me back to the moodle URL. Then the browser dies with a message stating that "too many redirects occurred trying to open..." the moodle login url.

It looks as if the redirect loop is between the moodle home page at /moodle and the moodle login at /moodle/login/index.php. I'm running the latest version of Moodle (2.5). I'm wondering if a setting that handles login within Moodle needs to be changed.

Once this happens I have no way of logging back in to moodle to even disable the drupalservices module. I end up having to remove the plugin from the moodle folders, then login to moodle, and clear the moodle cache.

I was running wincache and disabled it to make sure it wasn't interfering.

I was able to get the sync working with the following error message:

unable to update database.

Haven't gotten to that one yet.

Where do I go from here with this? Help!

How to match Drupal and Moodle super admins?

Hi,
How can I match Drupal and Moodle super admins?
Below is the error I'm getting when I try to login to Moodle as Drupal super admin.
It works fine with other accounts.

Debug info: Duplicate entry '1-admin' for key 'mdl_user_mneuse_uix'
INSERT INTO mdl_user (auth,mnethostid,lang,firstname,lastname,email,city,country,description,username,idnumber,confirmed,deleted,suspended) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => 'drupalservices',
1 => '1',
2 => '',
3 => 'Admin',
4 => 'Admin',
5 => 'Amin',
6 => 'Chicago',
7 => 'Us',
8 => '',
9 => 'admin',
10 => '1',
11 => 1,
12 => 0,
13 => 0,
)]
Error code: dmlwriteexception
-------------------------------------------------------------------------
Stack trace:
line 446 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1164 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1210 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 209 of /auth/drupalservices/auth.php: call to mysqli_native_moodle_database->insert_record()
line 122 of /auth/drupalservices/auth.php: call to auth_plugin_drupalservices->create_update_user()
line 89 of /login/index.php: call to auth_plugin_drupalservices->loginpage_hook()

Thanks,

Vjeko

Need maturity and release information

when registering this plugin in the new moodle plugin directory, the following warnings were thrown:

Warning Maturity information ($plugin->maturity) not found in version.php
Warning Release name ($plugin->release) not found in version.php

Not redirecting to Moodle after logging in when "destination" is used in the login URL

When I go to a Moodle page that requires logging in, it does send me back to drupal with the destination at the end of the URL, e.g.:

Moodle is on study.example.org
Drupal is on dev.example.org

http://dev.example.org/user/login?destination=course/view.php?id=2

So that part is working.

And then I'm guessing that once you've logged in it's supposed to send you to the Moodle URL with the destination appended, but this doesn't happen for me. Once logged in, it will send me to the Drupal URL with the destination appended.

So when logging in with the above URL, I get sent to:

http://dev.example.org/course/view.php?id=2

And that just gives me a page not found error.

I can find where the auth.php file appends the destination URL, but not where it's supposed to redirect it to after logging in, is this not fully implemented yet?

2.x-1.x-dev no longer working in Moodle 2.8.1/Drupal 7.34

Hello,

The 2.x-1.x-dev branch was working on Moodle 2.7/Drupal 7.31, but sometime in the latest upgrades to Moodle 2.8.1/Drupal 7.34 the sync_users function in auth.php stopped working. Upon further investigation I found that the $drupal_users = $apiObj->Index('muser'); object (on line 266) is showing "301 Moved Permanently". Can this error be easily fixed in the 2.x-1.x-dev branch or would it be easier to upgrade to the master branch?

I have been banging my head over this for the past few days so any help would be great!

Thanks,
Michael

PS. Due to my lack of familiarity with Drupal I have hesitated on updating to the master branch, but if necessary I can update.

Moodle 2.7.1+

Hi,

I'm using Moodle 2.7.1+ (Build: 20140724) and I'd like to ask if this addon still works with Drupal 7 and Moodle 2.7.1+?

Sync only 10 users

My drupal has alot of user and sync only 10 users. How can i fix it. I saw limit 10 once along time ago. But not now. Sorry for my english.

Error write to database if username already exist and idnumber is empty

Hi.

Environment:

• Drupal 7.21
• Moodle 2.4.2

  • Views 3.5
  • ctools 1.2
  • Services 3.3
  • Services Views 1.0-beta2
  • Libraries 2.1
  • Addressfield 1.0-beta3
  • Addressfield Tokens 1.3

The sync-script looks for existing uid in field idnumber, which is empty (Moodle has 2 users: admin & guest, both having empty idnumber after installtion of moodle).

Your script tries to create the user admin (which exists in Drupal and Moodle after fresh installations) - idnumber is empty, so the 'user is new'. The task ends with error "Error writing to database", cause: admin as username exists already in moodles user-DB.

Why is idnumber in moodle's DB empty for the default users?

This seems to be a bug for new installations: Your script fills this field after creation, I hope moodles does this too for future users.

So, the main problem are the empty idnumbers after a new Moodle installation.

A workaround: set the idnumber for the user to 1 (if default username in Drupal and Moodle matches).

Can you confirm that issue?

Add name conflict resolution

In both 1.x and 2.x, if a drupal user changes their username to a conflicting name in moodle, the sync script fails. some form of resolution needs to be added, and at a minimum, the script needs to continue on rather than stop all together.

Unable to sign-in

I have followed the instructions to the letter but I am still unable to login to Moodle with my Drupal username/password. I can run the sync script and it works with no errors. I log out of Moodle and Drupal, clear cache/cookies, and login to Drupal. When I navigate to Moodle, it doesn't automatically sign me in and when I try to sign-in with my username/password, I get an error message "Incorrect username/password." I am using Drupal 7 and Moodle 2.4.3+. Any guidance would be most welcome!

New user not pulled from drupal on Moodle login page

Very handy little plugin, thank you.

One error: starting at line 125 of auth.php, the plugin tries to pull a user that can't be found in the Moodle database from the Drupal services REST server. It then throws a DB write error.

This is because the apiObj doesn't log in as the $remote_user, and so gets a FALSE return.

The code should also handle the possibility of getting a FALSE return more gracefully, rather than assuming it will always receive a valid return.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.