I believe the error is occurring because the MoodleSessionTest cookie value is missing. I've modified the webservice call to generate a MoodleSessionTest value and return it, but it still throws the same error.
Is there a way to take the login data obtained by the web service and transfer it to the user? Thanks for any help.
The OKTech generated session value is separate to the MoodleSession value so you won't will be able to insert that into the MoodleSession cookie value directly. Usually the OKTech session is the "id" field value from a record inserted into the mdl_webservices_sessions table for the user, and is returned to the client in the SOAP payload, not as a Cookie as such.
Was this issue resolved?? I have the same need, will help if the solution is posted.
MooodleSession and MoodleTestSession are 2 out of the 3 cookies that Moodle login sets in the browser. Using OKTECH web services, you will get these values as part of the header (the client and sessionkey returned by the webservice cannot be used in this regards). Problem is, even if you set these cookie values correctly, you will not be able to get through, cause it seems, moodle won't allow a user whos authentication mechanism is Web Service to login via a browser based interface.
Not sure why this limitation, if had got around by using the same user/password to login via Web Service and via web, please share the solution.
>moodle won't allow a user whos authentication mechanism is Web Service to login via a browser based interface.
Yes this is the way it should be. OKTech WS (and Moodle 2.0 official WS) have been initially designed to allow external Information Systems to access Moodle's entities (accounts, courses, activities...) thus the account used to log in may have some capabilities that you will not give to a regular Moodle user connecting from the Web interface. Do you really want to disclose a Moodle admin username/password to developers of your University IS , so they can login in to your Moodle by Web and mess it up ???
So you can connect to Web Service in two ways :
- using a regular Moodle user account (manual, ldap) but in that case you will get no more rights that you would have with the Web interface.
- using a specific Webservice account, with possibly extra rights, but in that case only via Soap calls, not Web ...
Thanks Patrick for your response.
I want users to have same privileges and use their own user/password. There seems to be a bit of issue, if I use the web service with the #1 method mentioned above. Not sure if it's a setup issue with my moodle instance, a user with authentication type of Manual cannot login via the OKTECH webservice (get invalid user error). When I switch the authentication type of the user to auth_WebService, then I am able to login via the webservice, but it has a problem: if HTML topic contains images, the webservice will return the html text which includes path to the images. There seems to be no easy way to display the images using the path. If I set the MoodleSession and MoodleSessionTest cookies of my mobile client using the cookies of a user logged via web and show the HTML topic content, the images show correctly, but setting the same cookies with the data received from the login webservice header, blocks the images from showing.
Sorry but I don't understand what you are trying to do and how you do it. The Web Service is not meant to login and browse a Moodle site, but to realize operations such as get_my_courses, add_course, add_user , enrol_user, add_group, add_user_togroup ... as described in the WSDL.
>if I use the web service with the #1 method mentioned above. Not sure if it's a setup issue with my moodle instance, a user with authentication type of Manual cannot login via the OKTECH webservice (get invalid user error)
To login to the Web Service you must call by a Soap client the operation login(username,password)
>if HTML topic contains images, the webservice will return the html text which includes path to the images.
What HTML topic ?
Let me attempt to describe the problem in a different way.
I do use the webservice login function to login and get the client and sesskey as a return. I agree with the usage of web services for getting courses, sections, users...
The point I was trying to make is, courses in moodle can have topics. Topics can have resources of type HTML. And the HTML that is loaded as a topic can have images in it. You can use the "get_sections" function to get the topics under a course and "get_resources" to get the resources associated with the topics. The output of get_sections will tell you the sequence in which the resources appear. Images are loaded in moodle and will have a url of something like
If I have 2 users enrolled in the same course, one (user1) with authentication type of manual and the other (user2) with authentication type of webservices. If I use user1's credentials in the web service or user2's credentials for login via browser I get an "invalid user" error. They have to be used in their respective authentication types to login successfully. This seems to be the how moodle authentication works.
Here's the problem: The "get_resources" function of web services will give me the contents of the html file uploaded (as "alltext" tag). That html file also contains the path to the images. Now if I have to render this html on a mobile device using the data I received from the webservice, I need to render the images as well. Is there a way to get access to these images to user2 (with authentication method of web service). When user1 visits the same course via browser, he sees the content properly.
If I use the MoodleSession and MoodleSessionTest cookies of user1 and hardcode them into the mobile version of my moodle client, the images show up properly as well on my mobile device. I am looking for a way where user2 can see the contents, as user1 would see in the browser. If manual and webservice authentications were treated similar in giving access to resources, the problem would be solved or if user2 could login both via browser and via webservice at the same time, this problem could be solved. Hope I was able to clearly state the problem.