Have been working on a test client in Flex 3 for the web services. Right now it seems that development of web services has mainly been concerned with the first of the two use cases below :
- administrating your moodle web site using an external application of some type. Administering users, courses etc.
- using web services for client side code embedded in a web page served to the user to communicate with the server.
I think that to enable developers to be able to build client side dynamic code that communicates through web services we need to do two things.
Enable authentication through passing a token into applet/object embedded in the web page
In the case that web services are used by an external application I understand it is planned that a username and password is entered into the external app and then sent by a web service to the server as a web service call, then an authentication token is sent back as the result from the web service call. The token is then passed along with all subsequent service calls to identify the user.In the case that an applet or object is embedded into the page possibly the same token could be passed directly into the applet/object. This would mean including the token in the html that is used to embed the object would include appropriate tags to pass the token into the applet / object along with the url of the web services. We need a function to call in php that would return such a token so that developers can write php that embeds applets/object into the page. This token would be a randomly generated string of some sort, which is temporarily valid.
Associate a context with a authentication token
It would seem a good thing to associate a context with the authentication token. This would mean that we know all web service calls from for example client side code in an activity, block, etc is related to that activity/block. The token has been generated on the server side and when the web services related to the activity/block etc are called then we know that these calls are from this activity and web service calls cannot be spoofed to interfere with other activities.External apps could allow the user to log in with appropriate user details to get access to the whole system.
Limiting the web services that can be called from within client side code embedded in an activity / block html - not essential but desirable??
It would seem that if code is called from within an activity / block - code that uses this mechanism of having a token passed directly into the activity will never need to call the web services designed to be used by an admin to manage the moodle web site.I think that web services designed to be called from client side code should be in a different file in the mod/{activity} or block/{blockname} directories than external.php. external.php will be used for administrative type web service functions. Code callable from within a client side app will look for a file of another file name in the mod/{activity} or block/{blockname} directories which will be used in the same way. Only the web services exposed in this file will be available to the client side code.
Of course access to web services is already controlled by checking capabilities of the user. And applets/object embedded in a web page and passed a token to access web services will not hopefully include malicious code but this will provide an extra level of protection and seperation seems sensible as the functionality needed is fundamentally different.