[comment]: # ({43f8bc43-43f8bc43})
# 检查认证

[comment]: # ({/43f8bc43-43f8bc43})

[comment]: # ({3c28b1f2-a9b9d697})

### 描述

`object user.checkAuthentication`

此方法检查并延长用户会话。

::: noteimportant
默认情况下，使用参数 'sessionid' 调用 'user.checkAuthentication' 会延长用户会话。
:::

[comment]: # ({/3c28b1f2-a9b9d697})

[comment]: # ({22aef924-49a0b391})
### 参数

该方法接受以下参数。

|参数|[类型](/manual/api/reference_commentary#data-types)|说明|
|--|--|------|
|extend|boolean|是否延长用户会话。<br><br>默认值："true"。<br>将该值设置为 "false" 可在不延长会话的情况下检查用户会话。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 如果设置了 `sessionid`，则*支持*|
|sessionid|string|用户[认证令牌](/manual/api#authentication)。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 如果未设置 `token`，则为*必需*|
|token|string|用户 [API 令牌](/manual/api#authentication)。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 如果未设置 `sessionid`，则为*必需*|

[comment]: # ({/22aef924-49a0b391})

[comment]: # ({b0d25373-a8544e3e})
### 返回值

`(object)` 返回一个包含用户信息的对象。

除[标准用户属性](object#user)外，还会返回以下信息。

|属性|[Type](/manual/api/reference_commentary#data-types)|描述|
|--|--|------|
|auth\_type|integer|用户的默认认证方式。<br><br>有关可能的值列表，请参见[认证对象](/manual/api/reference/authentication/object#authentication-object)的 `authentication_type` 属性。|
|debug\_mode|integer|是否为用户启用或禁用调试模式。<br><br>有关可能的值列表，请参见[用户组对象](/manual/api/reference/usergroup/object#user-group)的 `debug_mode` 属性。|
|deprovisioned|boolean|用户是否属于[已取消配置用户组](/manual/web_interface/frontend_sections/users/authentication#configuration)。|
|gui\_access|string|用户访问前端的认证方法。<br><br>有关可能的值列表，请参见[用户组对象](/manual/api/reference/usergroup/object#user-group)的 `gui_access` 属性。|
|secret|string|随机的 32 个字符字符串。在用户登录时生成。<br><br>如果使用 API token 检查用户会话，则不会返回 `secret` 属性。|
|sessionid|string|认证令牌，必须在后续 API 请求中使用。<br><br>如果使用 API token 检查用户会话，则不会返回 `sessionid` 属性。|
|type|integer|用户类型。<br><br>有关可能的值列表，请参见[角色对象](/manual/api/reference/role/object#role)的 `type` 属性。|
|userip|string|用户的 IP 地址。|

[comment]: # ({/b0d25373-a8544e3e})

[comment]: # ({b41637d2-e79e2236})
### 示例

[comment]: # ({/b41637d2-e79e2236})

[comment]: # ({ed94544a-d574e685})
##### 使用认证令牌检查身份验证

使用用户认证令牌检查和延长用户会话，并返回有关用户的其他信息。

[请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "user.checkAuthentication",
    "params": {
        "sessionid": "673b8ba11562a35da902c66cf5c23fa2"
    },
    "id": 1
}
```

响应:

```json
{
    "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",
        "userdirectoryid": "0",
        "ts_provisioned": "0",
        "type": 3,
        "userip": "127.0.0.1",
        "debug_mode": 0,
        "gui_access": "0",
        "deprovisioned": false,
        "auth_type": 0,
        "sessionid": "673b8ba11562a35da902c66cf5c23fa2",
        "secret": "0e329b933e46984e49a5c1051ecd0751"
    },
    "id": 1
}
```

[comment]: # ({/ed94544a-d574e685})

[comment]: # ({45eaa4f3-698590d0})
##### 使用 API 令牌检查身份验证

使用用户 API 令牌检查用户会话，并返回有关该用户的附加信息。

[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "user.checkAuthentication",
    "params": {
        "token": "00aff470e07c12d707e50d98cfe39edef9e6ec349c14728dbdfbc8ddc5ea3eae"
    },
    "id": 1
}
```

响应：

```json
{
    "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": "1355919338",
        "rows_per_page": "50",
        "timezone": "Europe/Riga",
        "roleid": "3",
        "userdirectoryid": "0",
        "ts_provisioned": "0",
        "debug_mode": 0,
        "deprovisioned": false,
        "gui_access": "1",
        "mfaid": 0,
        "auth_type": 0,
        "type": 3,
        "userip": "127.0.0.1"
    },
    "id": 1
}
```

[comment]: # ({/45eaa4f3-698590d0})

[comment]: # ({e7148ebe-97f5ed87})
### 源代码

位于 *ui/include/classes/api/services/CUser.php* 中的 CUser::checkAuthentication()。

[comment]: # ({/e7148ebe-97f5ed87})
