# Login

Thông qua cơ chế đăng nhập, hệ thống có thể:

* **Xác thực (Authentication):** Kiểm tra thông tin đăng nhập (tên người dùng, mật khẩu, token, hoặc các cơ chế khác) để đảm bảo người dùng/thiết bị là hợp lệ.
* **Cấp quyền truy cập (Authorization):** Sau khi đăng nhập thành công, hệ thống sẽ gán quyền tương ứng với vai trò (role) hoặc phạm vi (scope) của tài khoản.
* **Bảo mật phiên làm việc (Session Security):** Quản lý vòng đời phiên đăng nhập bằng cách cấp access token/refresh token, hoặc cookie bảo mật, giúp duy trì kết nối an toàn trong suốt quá trình sử dụng dịch vụ.

{% hint style="success" %}
API SERVER:

⇒ <mark style="color:yellow;">**<https://apivcloud.innoway.vn>**</mark>
{% endhint %}

## POST /api/login

> Login

```json
{"openapi":"3.0.0","info":{"title":"Login","version":"1.0.0"},"servers":[{"url":"https://apivcloud.innoway.vn"}],"paths":{"/api/login":{"post":{"summary":"Login","tags":[],"parameters":[],"requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["identifier","password"],"properties":{"identifier":{"type":"string","format":"email"},"password":{"type":"string"}}}}}},"responses":{"200":{"description":"Login thành công","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LoginResponse"}}}},"400":{"description":"Login thất bại (sai identifier hoặc password)","content":{"application/json":{}}}}}}},"components":{"schemas":{"LoginResponse":{"type":"object","properties":{"token":{"type":"string","description":"JWT token để xác thực các request tiếp theo"},"expired_at":{"type":"integer","format":"int64","description":"Thời điểm token hết hạn (UNIX timestamp)"},"device_token":{"type":"string"},"is_admin":{"type":"boolean","description":"Người dùng có phải admin hay không"},"user_id":{"type":"string","format":"uuid","description":"ID người dùng"},"permissions":{"type":"array","description":"Danh sách quyền truy cập","items":{"$ref":"#/components/schemas/Permission"}},"email":{"type":"string","format":"email","description":"Email người dùng"},"system_role":{"type":"string","description":"Vai trò hệ thống (TENANT, USER)"},"refresh_token":{"type":"string","description":"Token để lấy access token mới"}},"required":["token"]}}}}
```

{% hint style="info" %}
{% code fullWidth="true" %}

```json
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

{% endcode %}

Khi login thành công "token" JWT sẽ được trả về.  Tất cà các api trên nền tảng đều yêu cầu mã xác thực trong headers dưới dạng : Bearer + token

```
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

{% endhint %}

## GET /api/token/refresh

> Refresh token

```json
{"openapi":"3.0.0","info":{"title":"Login","version":"1.0.0"},"servers":[{"url":"https://apivcloud.innoway.vn"}],"paths":{"/api/token/refresh":{"get":{"summary":"Refresh token","tags":[],"parameters":[{"name":"RefreshToken","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Refresh token thành công","content":{"application/json":{}}},"400":{"description":"Refresh token thất bại (token không hợp lệ hoặc hết hạn)","content":{"application/json":{}}}}}}}}
```


---

# Agent Instructions: 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:

```
GET https://innoway.gitbook.io/innoway/tai-lieu/api/rest-api/login.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
