Hi, I have done a web service to create users using the standard web service 'moodle_user_create_users', now I want to identify users who can access this web service requiring user name and password, if I get a token then the user can create users using this web service.
I am using Moodle 2.2 and I have seen this help,
How to get a user token
Moodle 2.2
Your client can call the script located in /login/token.php with a simple HTTP request. We highly recommend to do it securely with HTTPS. The required parameters are:
- username
- password
- service shortname - The service shortname is usually hardcoded in the pre-build service (db/service.php files). Moodle administrator will be able to edit shortnames for service created on the fly: MDL-29807. If you want to use the Mobile service, its shortname is moodle_mobile_app. Also useful to know, the database shortname field can be found in the table named external_services.
Call: https://www.yourmoodle.com/login/token.php?username=USERNAME&password=PASSWORD&service=SERVICESHORTNAME //Moodle mobile service shortname => moodle_mobile_app
Get in return: {token:4ed876sd87g6d8f7g89fsg6987dfh78d}
Difference between Moodle versions
- Moodle 2.2 and later: the script can generate user tokens for any service shortname (of course users must be allowed on the service, see How to create and enable a web service).
- Moodle 2.1: the script can only generate tokens for the official built-in mobile service. However the script can returns tokens for other services, they just need to have been previously generated.
About service shortname
At the moment a service can have a shortname if you:
- create the service as a built-in service (in db/services.php files)
- add the shortname manually in the DB. Note: we'll add the admin UI for shortname later (MDL-30229)
Then I have added the below code in the field 'db/services.php files',
'moodle_webservice_get_token' => array(
'classname' => 'core_webservice_external',
'methodname' => 'get_user_token',
'classpath' => '/login/token.php',
'description' => 'Return token',
'type' => 'read',
),
but I can't see in Moodle the new funtction, I think I have to do the last step, 'add the shortname manually in the DB', but I don't know how to do this.
Any help would be appreciated.
Best Regards.