Login returns 'Invalid Token - token not found'

Login returns 'Invalid Token - token not found'

by john felix -
Number of replies: 4

Hi,

 I am trying to login using the moodle api. I am using the following url to login

http://localhost:8888/moodle21/login/token.php?username=user&password=password&service=new

I have already created the user 'user', service 'new' with no required capability. I have also enabled web services in the plugins.

But I am still the same error

{"error":"Invalid token - token not found","stacktrace":null,"debuginfo":null,"reproductionlink":null}.

I am trying to find an answer for this question. Please help me to find the answer for this problem.

Average of ratings: -
In reply to john felix

Re: Login returns 'Invalid Token - token not found'

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Plugin developers Picture of Testers

See the last message in this post  

in 2.2, you can retrieve the token with login/token.php: http://docs.moodle.org/dev/Creating_a_web_service_client#How_to_get_a_user_token 

If I remember in 2.1 you can too, except that if you request a different service than the mobile one, the token needs to already exists. The script will not create a token for the user, even if the user has the capability to do it. This feature has been added since 2.2 (currently there:https://github.com/moodle/moodle/blob/master/login/token.php).

 

 

 

 

 

 

 

 

 

 

Average of ratings: Useful (1)
In reply to john felix

Re: Login returns 'Invalid Token - token not found'

by Blair Patterson -

This is a bug that I'm about to submit.

If you have access to your db, you need to set the 'shortname' field in the '{db_prefix}external_services' table - it doesn't seem to be set on the creation of the webservice, or there's no way to set it in the Edit Webservice page, not at least that I can see.

I just ran into the exact same issue today, after setting shortname, I was able to connect and get the proper token back.

HTH.

blair D.

In reply to Blair Patterson

Re: Login returns 'Invalid Token - token not found'

by Jérôme Mouneyrac -

Hi Blair,

there is already an issue for this: MDL-30229

Note that if you create a built-in service (db/services.php files), then you can set the shortname.