Thank you, Nathan. Appreciate your reply. I suppose I will implement something similar. Too bad there's no way to achieve this using the webservices but.. such is life
Re: Moodle login after remote authentication
Re: Moodle login after remote authentication
Just to update the thread in case anyone else is interested in a similar solution, what I ended up doing was:
0. use my SSO system to auth
1. use Moodle webservices to check whether a user with the same email as in the SSO system already exists and if not, create a proper user entry in Moodle's own DB
2. redirect to a custom page I created on the moodle end passing along a nonce param
3. on the custom page, the HTTP_REFERER is checked to verify it matches the SSO system and if not, die() is called
4. the nonce is checked to ensure its valid and die() is called is not
5.
// Prohibit login if email belongs to the prohibited domain.
if ($err = email_is_not_allowed($useremail)) {
throw new moodle_exception($err, 'auth_kaltura_sso');
}
$user = $DB->get_record('user',array('email' => $useremail, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id));
complete_user_login($user);
// redirect to moodle's index page with:
header('location: https://my.moodle.index');
Re: Export certain Profile data to Wordpress or create an API
Hi Jim, I need to do a similar work. Did you have any success on working with wordpress and moodle. I'm trying to retrieve some profile and courses where the user is enrolled from moodle database to a Wordpress Frontend. Did you find any solution o any clue to start from there?
Thanks
Step by step tutorial to create web service - create user - enrol user - REST
Here you will find clear instructions to create Web Services on Moodle.
I am not a Moodle expert so this tutorial targets the users who are not so familiar with this process. I have collected the information below from may different sources and I have eliminated their errors to give you an easy to follow tutorial together with a working example.
This tutorial creates a web service enabled to create a new user and then enroll this user to a course.
1) Create the user which will serve the web services. Go to:
Site Administrator > Users > Accounts > Add new user
Username: wsuser (user your own)
Password: (user your own)
Fill in the required fields.
2) Give the wsuser the appropriate role. Go to:
Site Administrator > Users > Permissions > Define roles
press the Add new role button
Select Role archetype = ARCHETYPE: Manager and press continue
On the form:
Web Service User
Context types where this role may be assigned: System/User/Category/Course
Leave the rest selections as they appear.
Capabilities
Add the following capabilities
webservice/rest:use
moodle/user:create
enrol/manual:enrol
enrol/category:synchronised
enrol/manual:unenrolself
Press Create this role button.
3) Assign System roles. Go to:
Site Administrator > Users > Permissions > Assign System Roles
Assign wsuser user.
4) Create the needed services. Go to:
Site Administrator > Plugins > Web Services > External Services
We need the two services below:
a) Create user - service
On custom services table press add.
Name: create_user
Short: create_user
Enabled should be checked
Authorized users only should be checked
Press show more
Search for capability moodle/user:create and select it.
Press add service.
This service has no functions
Add functions
Search for the core_user_create_user
Select it and press add function.
b) Enroll user - service
On custom services table press add.
Name: enrol_user
Short: enrol_user
Enabled should be checked
Authorized users only should be checked
Press show more
Search for capability enroll/manual:enrol and select it.
Press add service
This service has no functions
Add functions
Search for the enrol_manual_enrol_users
Select it and press add function.
On the list of custom services you have to add the authorized user to be the wsuser.
5) Create the Tokens. Go to:
Site Administrator > Plugins > Web Services > External Services > Manage Tokens
Add
a) Create User
Select user Web Service User
Service – create user
Save changes.
b) Enroll User
Select user Web Service User
Service – enrol user
Save changes.
You now have the two required tokens.
6) All web service protocols are disabled. The "Enable web services" setting can be found in Advanced features. Go to:
• Site Administrator > Advanced features > Enable web services checked – Save.
• Site Administrator > Plugins > Web Services > External Services > Manage Protocols.
Activate REST protocol.
Check the documentation box.
7) CURL.php is required on the client side. You may download it here.
8) Check if create user works using php code.
9) Check if enroll user works using php code.
10) The wsuser user can not assign role without being enrolled in the course/s!!!
You may download a fully workin php example from my site here.
Moodle Authentication Using an External Web Service
Hi, Folks,
I have an external web service for authentication in my company and I'd like to connect Moodle with it, but I'm not being able to do it.
When I activate the web service authentication plugin, I see the message that I cannot use it exclusively with web accounts.
Maybe it's a newbie or stupid question, but I didn't understand why... can y ou explain it?
Thanks,
Luiz
Re: Moodle Authentication Using an External Web Service
Hello,
as far as I know, the standard "webservices authentication" of Moodle is used to authenticate consumers of Moodle's webservices.
If you are interested in authenticating users against an external webservice, you may take a look at
https://github.com/danielneis/moodle-auth_ws/
It works with SOAP, but feel free to make it work with REST and other protocols and submit a pull request =)
Kind regards,
Daniel
Re: core_user_create_users causes "active database transaction detected during request shutdown" errors
Hi,
I had a similar problem with CAS authentication, launching moodle/auth/cas/cli/sync_users.php, exactly like in this thread.
Problem resolved using more PHP memory (512M to 1024M in my case ; memory_limit=1024M) to execute this script, as explained in this discussion
Séverin
using web service from one moodle to another moodle
I'm new with moodle and my senior ask me to do something.
I'm using two moodle. One moodle for the student study at home, I called it moodle study, and one moodle for the test, I call it moodle test. The moodle test running on local server so the student won't do the test outside the laboratory.But I want to make the student can see their test score from moodle test through the moodle study.
I'm thinking of using a gradebook plugin on moodle study which return the test score from moodle. Can I use moodle webservice to get the score value? If I can, what thing should I do first?
Sorry for my bad english. And thank you.
Re: Moodle Authentication Using an External Web Service
Hello,
after you install the plugin, you should see the new settings, but if it not happen, got to the following URL on your moodle:
moodle/admin/settings.php?section=manageauths
Enable the "External webservice authentication" plugin and click the link to go to it's settings, or access the following URL on your moodle:
moodle/admin/auth_config.php?auth=ws
Now, you will need the following from your SOAP webservice, in same order of settings page:
- The URL of your server. Note that the ?wsdl prefix will be added if needed.
- A set of parameters that may be sent in every call (maybe moodletoken:abfbFba5asas5cs5asc)
- The name of the function to use to authenticate users
- Name of the paramater to send username as to the webservice.
- Name of the paramater to send password as to the webservice.
- The name of the class containing the result of webservice.
- The field of the class containing boolean the result of webservice.
You may see an form with sample data at:
https://raw.githubusercontent.com/danielneis/moodle-auth_ws/master/moodle-auth_ws_settings.png
If you have any other doubts, please let me know.
Kind regards,
Daniel
Re: using web service from one moodle to another moodle
Hello,
I've worked with a similar project.
The solution we use is to export a backup file to the "study moodle".
More technically, you can take a look at
https://tracker.moodle.org/browse/MDL-47776
The whole project description and documentation is at:
https://gitlab.setic.ufsc.br/moodle-provas/blocks-exam_actions/wikis/moodle_provas
It's written in Brazilian portuguese, but if you have interest, we can make an english version.
Basically, we have the same division of "study moodle" and "test moodle" that we call "remote moodle" and "exam moodle", repectively.
We have developed 3 plugins so you can link how many "study moodles" you want and automagically create "exam courses" in "exam moodle" for the courses you have at your "study moodles" (the courses are created with the same name and the enrols are synced), there are capabilities mapping for which people in each user can create these courses, monitor the exam (log in into moodle during the exam time) and take the exam.
We also use a custom Ubuntu distribution that boots up from a pendrive, a cd-rom or remote via local network, and only gives users a browser the can only access the exam moodle IPs, and user cannot access any media from the machine, unless some minor configurable exceptions.
The plugins also implements a "temporary key" feature that is generated by the exam monitor at the time of the exam that students must provide to authenticate along with its usual username and password.
It is all open source and it will be great to share it with a bigger community.
Kind regards,
Daniel
Re: Moodle Authentication Using an External Web Service
Hi, Daniel,
I tried to install it using plugin install option, but I got an error message of name mismatch.
I unzipped, renamed plugin's main directory as "auth_ws" and tried again. This time I got a different error message (see added file).
By the way, I'm using 2.9.1 version.
Thank you.
Luiz
Re: Moodle Authentication Using an External Web Service
Hello,
don't know about this install option, and because the plugin still is not on plugins database, it really should not work.
You must put the code in moodle/auth/ws and it will work =)
Kind regards,
Daniel
Re: using web service from one moodle to another moodle
Hi Daniel,
I interest with your plugin. I would like to read the English version to know if I can implement it on the system. Thank you, Daniel for your answer.
Regards,
Juwita
Can we please remove core_grade_get_grades webservice?
It cannot be fixed properly to return manual grade items and category items, because the return signature has hardcoded "activityid" and not "gradeitemid" and already existing hacks to insert the word "course" in the activityid response.
A proper useful function to retrieve student grades would be great - it would need https://tracker.moodle.org/browse/MDL-50582 to land first.
Re: Can we please remove core_grade_get_grades webservice?
Do we have a good deprecation process for web service functions?
If this was a Moodle internal API, we would
- Implement the new function / class / whatever API change.
- Modify the old functions so that using them causes a warning message.
- Announce in the release notes for that Moodle release that the old API is now deprecated.
- A few Moodle releases later, remove the old API.
- Announce in the release notes for that Moodle release that the old API is now gone.
That is a good system. Can we come up with an equivalent for web service APIs?
The only place I can think of to put the warning message is in the PHP logs on the Moodle server, and they are highly likely to not be seen. However, I hope there is a better option that I have failed to think of.
Determining Cohorts that a User is a Member Of (Webservices)
After researching the Moodle webservices, I can not seem to find one that will return a listing of what cohorts a given user is a member of. Am I missing something? We can use core_cohort_get_cohort_members to get the members for a specific cohort, but it wouldn't be very efficient to have to get the membership of all cohorts, and then parse through it looking for a single user.
It appears we currently have:
2.4 - core_cohort_get_cohorts
2.4 - core_cohort_create_cohorts
2.4 - core_cohort_update_cohorts
2.4 - core_cohort_delete_cohorts
2.4 - core_cohort_get_cohort_members
2.4 - core_cohort_add_cohort_members
2.4 - core_cohort_delete_cohort_members
In essence I am looking for a webservices wrapper for SQL similar to:
SELECT u.id,u.username, u.firstname, u.lastname, hm.cohortid, h.idnumber, h.name
FROM prefix_cohort AS h
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid
JOIN prefix_user AS u ON hm.userid = u.id
WHERE u.id='insert moodle userid'
SELECT u.id, u.username, u.firstname, u.lastname, hm.cohortid, h.idnumber, h.name
FROM prefix_cohort AS h
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid
JOIN prefix_user AS u ON hm.userid = u.id
WHERE u.username='insert username'
I guess it could also be argued that maybe this information should be returned as part of:
2.5 - core_user_get_users_by_field
Thanks for any thoughts you might have!
Re: Can we please remove core_grade_get_grades webservice?
The way this was done previously was just through the description of the method in the db/services.php which is shown in the webservices api documentation pages.
E.g. "DEPRECATED: this deprecated function will be removed in a future version. This function has been renamed as core_webservice_get_site_info()"
Re: Can we please remove core_grade_get_grades webservice?
Re: Can we please remove core_grade_get_grades webservice?
Well, it definitely looks like we should deprecate this function, and create a non-bonkers function that does the job right.
Re: Can we please remove core_grade_get_grades webservice?
+1 to remove that function
As an alternative, I implemented this function: https://github.com/moodle/moodle/blob/MOODLE_29_STABLE/grade/report/user/externallib.php#L64 to retrieve the gradebook for users.
Note that this function rely in the report API, the information returned is not ready to be treated by external SIS but it's useful if you want to build a visual representation of the user gradebook.
Regards, Juan