> For the complete documentation index, see [llms.txt](https://doc.ozforensics.com/oz-knowledge-ru/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.ozforensics.com/oz-knowledge-ru/rukovodstva/rukovodstvo-razrabotchika/api/oz-api/autentifikaciya-i-obrabotka-dannykh/tokens.md).

# Аутентификация

## **Аутентификация пользователя**

Чтобы получить токены доступа, нужно выполнить `POST`-запрос на `/authorize/auth/`. В теле запроса нужно указать полученные от нас электронную почту и пароль в составе `credentials`, а также API-адрес в качестве адреса хоста.

Body

```json
{
	"credentials": {
		"email": "{{user_email}}",
		"password": "{{user_password}}"
	}
}
```

Результатом аутентификации пользователя является пара `access_token` и `expire_token`.

**access\_token** — ключ (набор символов), предъявление которого является пропуском к ресурсам системы. Обращение к ним происходит с указанием в заголовках полученного `access_token`.

`headers = {‘ X-Forensic-Access-Token’: <access_token>}`

Действие **access\_token** ограничено во времени и регулируется [настройками](/oz-knowledge-ru/rukovodstva/rukovodstvo-administratora/configuration.md#taimingi-i-ogranicheniya):

* для сервисных учетных записей — `OZ_SESSION_LONGLIVE_TTL` (по умолчанию 5 лет),
* для всех остальных — `OZ_SESSION_TTL` (по умолчанию 15 минут).

**expire\_token** предназначен для обновления пары access\_token и expire\_token.

### **Автопродление сессий**

если `expire_date` > текущей даты, то `expire_date` сессии устанавливается в значение текущей даты + временная дельта настроек, описанных выше.

## Обновление токенов

Чтобы обновить пару `access_token` и `expire_token`, нужно выполнить `POST`-запрос на адрес `authorize/refresh/` c `expire_token` в теле запроса и `X-Forensic-Access-Token` в заголовках.

```json
{
    "expire_token": "{{expire_token}}"
}
```

<div align="left"><img src="/files/oWUnjaU99CKYLJM31x7X" alt=""></div>

Положительным результатом будет ответ с новой парой `access_token` и `expire_token`.\
Предыдущая пара `access_token` и `expire_token` будет удалена из базы данных при первой аутентификации по новой паре `access_token` и `expire_token`.

### Возможные ошибки

| **Код ошибки** | Сообщение об ошибке                                                        | Причина                                                                                        |
| -------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| 400            | Could not locate field for key\_path expire\_token from provided dict data | `expire_token` отсутствует в теле запроса.                                                     |
| 401            | Session not found                                                          | Не существует сессии с переданным `expire_token`.                                              |
| 403            | You have not access to refresh this session                                | Пользователь, который делает запрос, не является владельцем сессии переданного `expire_token`. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.ozforensics.com/oz-knowledge-ru/rukovodstva/rukovodstvo-razrabotchika/api/oz-api/autentifikaciya-i-obrabotka-dannykh/tokens.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
