Access control exceptions

Access control exceptions

by tim st.clair -
Number of replies: 0
Picture of Particularly helpful Moodlers Picture of Plugin developers

I am building a webservice that consumes the course completions data. I already have users authenticating from an external source, and need that system to be able to connect as those users and see their completion data. I've based this on the template webservice.

I've got my function and parameters all defined and in the format I want, and have registered the webservice and enabled it and its protocol (xmlrpc).

I created a token for a student, since this represents who I want to connect (e.g. student on external portal connects to moodle to consume results for themselves). I get the access warning:

Array
(
    [faultCode] => 23000021
    [faultString] => Access control exception | DEBUG INFO: You are not allowed to use the {$a} protocol (missing capability: webservice/xmlrpc:use) | ERRORCODE: accessexception
)

If I check Home > Site admin > Users > Permissions > check system permissions then sure enough, webservice.xmlrpc:use is not enabled for users.

So do I need to enable both moodle/webservice:createtoken and webservice/xmlrpc:use for students so that they can connect then consume the web service results? How do I do this programatically so that my auth-plugin can ensure that students are assigned these roles when the log on?

I set up a system role called 'xmlrpc' for webservice/xmlrpc:use, and then assigned my test student (which I had generated a token for in client.php test page), and then assigned that user to the systm role to see if that helped my service call - it did, however I now see the error:

Array
(
    [faultCode] => 28194976
    [faultString] => Calling parameters do not match signature | ERRORCODE: 
)

And I am not sure how to format my parameters so they work (e.g. I want it to have no parameters, but optionally one - the webservice template shows this but I can't make it work either).

The api documentation doesn't clearly show an end-to-end test case (or I'm looking in the wrong spot) - that is, as an external service, how to connect to generate a token, how to set up the roles in moodle to allow this, then use the token to talk to a web service in the context of that tokens user. Any assistance would be appreciated.

Average of ratings: -