Reputation: 2922
I am using the moodle web service. I am getting a token from '/login/token.php', but after I have that, what do I do with it? I cannot find documentation on how to get the userid from that token, or do anything with it.
Upvotes: 1
Views: 4458
Reputation: 2489
Don't know if this is way to old, but stumpled upon it myself. Maybe this can help other people too.
After you get the token, you have to supply it in your API calls. So let's say you have added the function to get all courses, then you can get the courses with the following REST URL:
/moodle/webservice/rest/server.php?wstoken=d4ffd83ce0e2602a458b44e16634ab17&wsfunction=core_course_get_courses
Where wstoken is the token you got. wsfuntion is the name of the service function.
I found a useful list of service functions in the moodle system:
moodle/admin/webservice/documentation.php
Here it's possible to see arguments and return values.
Upvotes: 2
Reputation: 1611
Take a look at function authenticate_user()
in moodle/webservice/lib.php this contains the methods to authenticate the user based on name+password or by token.
This calls the function authenticate_by_token
. This checks the external_tokens
table to see if your token is present and then finds out the user for this token and returns the authenticated user object.
I landed on this function when going through moodle/webservice/rest/server.php. I am using moodle stable release 2.8.2+ (Build: 20150123)
Upvotes: 1
Reputation: 416
if you have token then use this token on client.php script to check whether your web service is correct or not. whenever a user consumes this webservice then he/she need that token. Every web service function has a unique token.
To generate a token from UI just go through in your moodle site administrator->plugins->web services->manage token. then add your function and generate the token for that particular function.
Upvotes: 1
Reputation: 332
Token is a key to be used as authentication of web service consumer who is going to be use it. It is associated with each function of web services.
Upvotes: 1