Create a user for a webservice automatically

Create a user for a webservice automatically

by Pablo Platt -
Number of replies: 1

My plugin need to let an external web service talk to moodle. Asking the admin do all the steps manually is a bit cumbersome and much more difficult than just configuring three fields for a usual plugin. Is it ok to do the following automatically in the plugin install.php or are there technical or security issues?

 

  • Create a webservice user
  • Create a system role with the required capabilities
  • Assign the system role to the user
  • Give the user permission to use the web service
  • Generate a token for that user

Is there an example that does a similar thing?Am I missing some steps?

Thanks

Average of ratings: -
In reply to Pablo Platt

Re: Create a user for a webservice automatically

by Martin Mastny -
Picture of Core developers Picture of Peer reviewers Picture of Testers

Hello Pablo,

I was also experiencing this kind of issue. My problem was, that my plugin was just for teachers, so when somebody is assigned as a teacher I also have to assign a web service user role to him. I solved this by creating a simple DATABASE TRIGGER that inserts another role to mdl_role_assignments.

You can generate a token for user on the fly :

http://docs.moodle.org/dev/Creating_a_web_service_client#How_to_get_a_user_token 

Hope this helps

Martin