missingparam: token

missingparam: token

by Benjamin Greiner -
Number of replies: 7

Hi there,

i use moodle 3.8.2+ (Build 20200312, latest Adaptable Theme) which is hosted on a Synology DS918+ with DSM 6.2.2. (Linux based OS). Apache 2.4 is set up as web server together with PHP 7.3.11 and a Maria DB 10.3.

I have now come across the following problem:  As soon as you log in via Mobile App (3.8.2), the web server displays an error message if debug messages are activated:
[19-Apr-2020 13:39:05 Europe/Amsterdam] Default exception handler: Necessary parameter "token" missing Debug: 
Error code: missingparam

  • line 494 of /lib/setuplib.php: moodle_exception thrown
  • line 562 of /lib/moodlelib.php: call to print_error()
  • line 45 of /webservice/pluginfile.php: call to required_param()
When trying to locate the cause of the error according to the instructions described in the thread "Moodle Mobile debugging WS requests", the error can be reproduced, but no corresponding entries were found in the token*.php or server*.php files. The error is also triggered when, for example, the course page also changes. The error can be reproduced at any time even if the Boost-Theme is activated.

While searching for solutions, I found the article MOBILE-2718 in the Moodle Tracker. However, I did not find any direct connection. 

I would be very grateful for further help.

Average of ratings: -
In reply to Benjamin Greiner

Re: missingparam: token

by Noel De Martin -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi there,

What do you mean when you say "no corresponding entries were found in the token*.php or server*.php files"? I understand that you didn't see the error in the network requests, which is weird. If we assume the error is triggered in a request from the mobile app you should see it when inspecting the network.

Can you share the url to you moodle site? Maybe I can check it out.
In reply to Noel De Martin

Re: missingparam: token

by Benjamin Greiner -
Hi Noel,
thank you for your quick response. You heard me right. I have done the test many times and once or twice it has been output to a token.php file in the network requesets, but this cannot be reproduced.
The only thing I can say for sure is that after logging in with a mobile app or the desktop app the error (with activated debug messages) will be reproducibly output by the web server into the log file. If I repeat the same steps on the web page everything is fine.
Thank you very much for your help - I have sent you the URL by email.
Regards, Benny
In reply to Benjamin Greiner

Re: missingparam: token

by Noel De Martin -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Ok, I found the origin of the problem smile. This is happening because an image is loaded without the authentication token.

In the mobile app, we process assets such as images to include authentication tokens. Sometimes, these assets get loaded before we process them and that generates an unauthenticated request which is the source of that error. In any case, a subsequent authenticated request will be executed, so users shouldn't be noticing this. But it causes unnecessary network requests and misleading error logs like yours.

I've opened an issue to keep track of this, thanks for your help to debug it!
In reply to Noel De Martin

Re: missingparam: token

by Benjamin Greiner -

Hi Noel,
first of all thank you for your time and your support. I've looked at the log data again and I'm afraid that there is another problem. 
If I understand you correctly, your statement refers to the cover picture which is loaded twice for the reasons you mentioned. Interestingly, your analysis yesterday poped up some more error messages that I'm not sure if they are related to the problem you described.

The following errors were reported in the Moodle log files:

  • 20 April 2020, 17:13 - - Core system core system core system web service login failed Web service authentication failed with code: "invalid_token". ws
  • 20 April 2020, 17:13 - - Core system core system core system web service login failed Web service authentication failed with code: "invalid_token". ws

These coincide with the following actions:

  • 20 April 2020, 17:12 XXX - Core system Core system Core system user is logged in The user with id '20' has logged in. web
  • 20 April 2020, 17:13 XXX XXX Users: XXX Core System User Password updated The user with id '20' changed their password. web
  • 20. April 2020, 17:13 XXX Home Core System Course displayed The user with id '20' viewed the course with id '1'. web
  • 20 April 2020, 17:14 XXX XXX Core system Core system Core system Core system Web service token created The user with id '20' created a web service token for the user with id '20'. web

The web server has also issued several error messages:

[20-Apr-2020 17:13:59 Europe/Amsterdam] Default exception handler: A required parameter (username) was missing Debug: 
Error code: missingparam
line 494 of /lib/setuplib.php: moodle_exception thrown
line 562 of /lib/moodlelib.php: call to print_error()
line 34 of /login/token.php: call to required_param()


[20-Apr-2020 17:13:59 Europe/Amsterdam] Default exception handler: A required parameter (username) was missing Debug: 
Error code: missingparam
line 494 of /lib/setuplib.php: moodle_exception thrown
line 562 of /lib/moodlelib.php: call to print_error()
line 34 of /login/token.php: call to required_param()


[20-Apr-2020 17:13:59 Europe/Amsterdam] Default exception handler: A required parameter (username) was missing Debug: 
Error code: missingparam
line 494 of /lib/setuplib.php: moodle_exception thrown
line 562 of /lib/moodlelib.php: call to print_error()
line 34 of /login/token.php: call to required_param()


[20-Apr-2020 17:13:59 Europe/Amsterdam] Default exception handler: A required parameter (username) was missing Debug: 
Error code: missingparam
line 494 of /lib/setuplib.php: moodle_exception thrown
line 562 of /lib/moodlelib.php: call to print_error()
line 34 of /login/token.php: call to required_param()


[20-Apr-2020 17:14:13 Europe/Amsterdam] Default exception handler: A required parameter (token) was missing Debug: 
Error code: missingparam
line 494 of /lib/setuplib.php: moodle_exception thrown
line 562 of /lib/moodlelib.php: call to print_error()
line 45 of /webservice/pluginfile.php: call to required_param()


Furthermore, I conducted another test. I have loaded a course page with the Moodle desktop app where no errors occurred in the network requests while loading the images. Nevertheless the web server displayed the error message described above several times (missingparam: token).

Is there a connection to the problem you have described or do you think there is another problem? 

Just in case, I have enrolled you in a test course where in my opinion no images are loaded twice but the error message (missingparam: token) is triggered several times.I hope I do not strain your patience too much smile.

Regards,
Benny

In reply to Benjamin Greiner

Re: missingparam: token

by Noel De Martin -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hey no problem, thanks for your interest smile.

I've been looking further into requests made from the app and I've found another thing to improve, which I've reported here. Turns out in order to see if the url introduced in the login screen is a moodle site, we're calling /login/token.php without any parameters, as you can see here. That is a problem because a normal login will always generate that error that you are seeing "A required parameter (username) was missing ". Even if that's the expected behaviour, I don't think it should generate error logs. Specially if that happens every time anyone logs in.

The other errors you are seeing are probably the same as before, because "A required parameter (token) was missing" and "Web service authentication failed with code: "invalid_token"" are both triggered from pluginfile.php without the token. And that's the url for assets. Maybe it wasn't the course image but it could have been some css, some js file or something else.

I've also noticed that some errors return a 200 response (for example calling the /login/token.php), but looking at the returned json you can see the error data. I haven't seen anything out of the ordinary browsing the course.
In reply to Noel De Martin

Re: missingparam: token

by Benjamin Greiner -
Hi Noel,
thanks for the infos and for looking at the matter again smile.
Regards,
Benny
In reply to Benjamin Greiner

Re: missingparam: token

by Greicy Barreto -
I have a problem whit my moodle 4.0

Got error 'PHP message: Default exception handler: Un par\xc3\xa1metro necesario (token) faltaba Debug: \nError code: missingparam\n* line 497 of /lib/setuplib.php: moodle_exception thrown\n* line 592 of /lib/moodlelib.php: call to print_error()\n* line 45 of /webservice/pluginfile.php: call to required_param()\n', referer:http://localhost/

I dont understant. My moodle is slow.

Thanks