Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moodle 2.9.1 -- Any web service function gives 'access control exception'

Following various guides, I have managed to accomplish the following:

  • Set up an external service using the REST API which includes the "core_user_create_users" function,
  • Set up a user account and assigned it to be allowed to use the REST API service I set up,
  • Defined a role for web service users, archetype 'authenticated user', context of 'system',
  • Set role to allow "moodle/user:create", and
  • Manually generated a token for the web service user with no expiration.

Now, when I go to the built-in web service test client, select to use token-based authentication on the REST API, select the "moodle_user_create_users" function and put in the token and details, I get this:

REST protocol: moodle_user_create_users
URL: [...]
'<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="webservice_access_exception">
<ERRORCODE>accessexception</ERRORCODE>
<MESSAGE>Access control exception</MESSAGE>
<DEBUGINFO>Access to the function moodle_user_create_users() is not allowed.
There could be multiple reasons for this:
1. The service linked to the user token does not contain the function.
2. The service is user-restricted and the user is not listed.
3. The service is IP-restricted and the user IP is not listed.
4. The service is time-restricted and the time has expired.
5. The token is time-restricted and the time has expired.
6. The service requires a specific capability which the user does not have.
7. The function is called with username/password (no user token is sent)
and none of the services has the function to allow the user.
These settings can be found in Administration &gt; Site administration
&gt; Plugins &gt; Web services &gt; External services and Manage tokens.</DEBUGINFO>
</EXCEPTION>

What am I missing?

like image 705
Luke G. Avatar asked Nov 26 '22 05:11

Luke G.


2 Answers

I had the same exception. then I have made this change in the admin dashboard.

Site administration -> Mobile app -> Mobile settings -> Enable web services for mobile devices.

turn this on.

that's who I solved my issue.

like image 71
MH Fuad Avatar answered Nov 28 '22 20:11

MH Fuad


My answer seems to be the same as others have experienced: the Web Service Test Client is hopelessly broken.

This was a known issue at the time I was working on this project, and unfortunately Moodle decided to continue to ship this feature anyway.

For the foreseeable future I'd suggest not wasting your time even trying to use this 'tool'.

like image 44
Luke G. Avatar answered Nov 28 '22 20:11

Luke G.