string/object user.login(object parameters)
Este método permite iniciar sesión en la API y generar un token de autenticación.
Al utilizar este método, también debe hacer user.logout para evitar el generación de un gran número de registros de sesiones abiertas.
Este método sólo está disponible para usuarios no autenticados. y debe ser llamado sin el parámetro auth
en la solicitud JSON-RPC.
(objeto)
Parámetros que contienen el nombre de usuario y la contraseña.
El método acepta los siguientes parámetros.
Parámetro | Tipo | Descripción |
---|---|---|
password (obligatorio) |
cadena | Contraseña de usuario. |
username (obligatorio) |
cadena | Nombre de usuario. |
userData | flag | Devuelve información sobre el usuario autenticado. |
user (obsoleto) |
cadena | Este parámetro está obsoleto; utilice username en su lugar.Nombre de usuario. |
(string/object)
If the userData
parameter is used, returns an object containing information about the authenticated user.
Additionally to the standard user properties, the following information is returned:
Property | Type | Description |
---|---|---|
debug_mode | boolean | Whether debug mode is enabled for the user. |
gui_access | integer | User's authentication method to the frontend. Refer to the gui_access property of the user group object for a list of possible values. |
sessionid | string | Authentication token, which must be used in the following API requests. |
userip | string | IP address of the user. |
If a user has been successfully authenticated after one or more failed attempts, the method will return the current values for the attempt_clock
, attempt_failed
and attempt_ip
properties and then reset them.
If the userData
parameter is not used, the method returns an authentication token.
The generated authentication token should be remembered and used in the auth
parameter of the following JSON-RPC requests. It is also required when using HTTP authentication.
Autenticar a un usuario.
Solicitud:
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"username": "Admin",
"password": "zabbix"
},
"id": 1
}
Respuesta:
Authenticate and return additional information about the user.
Request:
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"username": "Admin",
"password": "zabbix",
"userData": true
},
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"userid": "1",
"username": "Admin",
"name": "Zabbix",
"surname": "Administrator",
"url": "",
"autologin": "1",
"autologout": "0",
"lang": "ru_RU",
"refresh": "0",
"theme": "default",
"attempt_failed": "0",
"attempt_ip": "127.0.0.1",
"attempt_clock": "1355919038",
"rows_per_page": "50",
"timezone": "Europe/Riga",
"roleid": "3",
"type": 3,
"debug_mode": 0,
"userip": "127.0.0.1",
"gui_access": "0",
"sessionid": "5b56eee8be445e98f0bd42b435736e42"
},
"id": 1
}
CUser::login() en ui/include/classes/api/services/CUser.php.