Token

View as Markdown
# BizMail API 1.0 — Authentication --- ## 🇬🇧 English > **Note:** Username and password are generated in the **BizMail Portal**. Please log in to your account at the portal to obtain your credentials before calling these APIs. --- ### 1\. Generate Token **`POST /api/1.0/auth/token`** Generate a JWT access token and refresh token using your BizMail Portal credentials. #### Headers | Key | Value | Required | | --- | --- | --- | | Content-Type | application/json | ✅ | #### Body (JSON) | Field | Type | Required | Description | | --- | --- | --- | --- | | username | string | ✅ | Username created in BizMail Portal | | password | string | ✅ | Password created in BizMail Portal | #### Example Request ``` json { "username": "user@example.com", "password": "your_password" } ``` #### Responses **200 OK — Success** ``` json { "success": true, "access_token": "<jwt_access_token>", "refresh_token": "<jwt_refresh_token>", "token_type": "Bearer", "expires_in": 86400 } ``` | Field | Type | Description | | --- | --- | --- | | access_token | string | JWT token for API authentication. Expires in **1 day** | | refresh_token | string | Token used to renew the access token. Expires in **90 days** | | token_type | string | Always `Bearer` | | expires_in | integer | Access token lifetime in seconds (86400 = 1 day) | **400 Bad Request** ``` json { "success": false, "message": "username and password are required" } ``` **401 Unauthorized** ``` json { "success": false, "message": "Invalid credentials" } ``` **500 Internal Server Error** ``` json { "success": false, "message": "Internal server error" } ``` --- ### 2\. Refresh Token **`POST /api/1.0/auth/refresh`** Use the `refresh_token` to get a new pair of access token and refresh token without re-entering credentials. #### Headers | Key | Value | Required | | --- | --- | --- | | Content-Type | application/json | ✅ | #### Body (JSON) | Field | Type | Required | Description | | --- | --- | --- | --- | | refresh_token | string | ✅ | The refresh token received from `/auth/token` | #### Example Request ``` json { "refresh_token": "<jwt_refresh_token>" } ``` #### Responses **200 OK — Success** ``` json { "success": true, "access_token": "<new_jwt_access_token>", "refresh_token": "<new_jwt_refresh_token>", "token_type": "Bearer", "expires_in": 86400 } ``` **400 Bad Request** ``` json { "success": false, "message": "refresh_token is required" } ``` **401 Unauthorized — Token expired** ``` json { "success": false, "message": "Refresh token expired" } ``` **401 Unauthorized — Invalid token** ``` json { "success": false, "message": "Invalid refresh token" } ``` --- ### Usage Flow ``` 1. Call POST /api/1.0/auth/token → get access_token + refresh_token 2. Use access_token in all API requests: Authorization: Bearer <access_token> 3. When access_token expires (after 1 day): Call POST /api/1.0/auth/refresh → get new access_token + refresh_token 4. When refresh_token expires (after 90 days): Repeat step 1 ``` --- --- ## 🇻🇳 Tiếng Việt > **Lưu ý:** Username và password được tạo trên **BizMail Portal**. Vui lòng đăng nhập vào tài khoản của bạn trên portal để lấy thông tin đăng nhập trước khi gọi các API này. --- ### 1\. Lấy Token **`POST /api/1.0/auth/token`** Tạo JWT access token và refresh token từ thông tin đăng nhập trên BizMail Portal. #### Headers | Key | Value | Bắt buộc | | --- | --- | --- | | Content-Type | application/json | ✅ | #### Body (JSON) | Tham số | Kiểu | Bắt buộc | Mô tả | | --- | --- | --- | --- | | username | string | ✅ | Username được tạo trên BizMail Portal | | password | string | ✅ | Password được tạo trên BizMail Portal | #### Ví dụ Request ``` json { "username": "user@example.com", "password": "your_password" } ``` #### Responses **200 OK — Thành công** ``` json { "success": true, "access_token": "<jwt_access_token>", "refresh_token": "<jwt_refresh_token>", "token_type": "Bearer", "expires_in": 86400 } ``` | Trường | Kiểu | Mô tả | | --- | --- | --- | | access_token | string | JWT token dùng để xác thực API. Hết hạn sau **1 ngày** | | refresh_token | string | Token dùng để gia hạn access token. Hết hạn sau **90 ngày** | | token_type | string | Luôn là `Bearer` | | expires_in | integer | Thời hạn access token tính bằng giây (86400 = 1 ngày) | **400 Bad Request** ``` json { "success": false, "message": "username and password are required" } ``` **401 Unauthorized** ``` json { "success": false, "message": "Invalid credentials" } ``` **500 Internal Server Error** ``` json { "success": false, "message": "Internal server error" } ``` --- ### 2\. Refresh Token **`POST /api/1.0/auth/refresh`** Dùng `refresh_token` để lấy cặp token mới mà không cần nhập lại username/password. #### Headers | Key | Value | Bắt buộc | | --- | --- | --- | | Content-Type | application/json | ✅ | #### Body (JSON) | Tham số | Kiểu | Bắt buộc | Mô tả | | --- | --- | --- | --- | | refresh_token | string | ✅ | Refresh token nhận được từ `/auth/token` | #### Ví dụ Request ``` json { "refresh_token": "<jwt_refresh_token>" } ``` #### Responses **200 OK — Thành công** ``` json { "success": true, "access_token": "<new_jwt_access_token>", "refresh_token": "<new_jwt_refresh_token>", "token_type": "Bearer", "expires_in": 86400 } ``` **400 Bad Request** ``` json { "success": false, "message": "refresh_token is required" } ``` **401 Unauthorized — Token hết hạn** ``` json { "success": false, "message": "Refresh token expired" } ``` **401 Unauthorized — Token không hợp lệ** ``` json { "success": false, "message": "Invalid refresh token" } ``` --- ### Luồng sử dụng ``` 1. Gọi POST /api/1.0/auth/token → nhận access_token + refresh_token 2. Dùng access_token cho tất cả API request: Authorization: Bearer <access_token> 3. Khi access_token hết hạn (sau 1 ngày): Gọi POST /api/1.0/auth/refresh → nhận access_token + refresh_token mới 4. Khi refresh_token hết hạn (sau 90 ngày): Lặp lại bước 1 ```

Request

This endpoint expects a multipart form.
usernamestringRequired
passwordstringRequired

Response headers

x-powered-bystring
etagstring
front-end-httpsstring
strict-transport-securitystring

Response

OK
successboolean
access_tokenstring
refresh_tokenstring
token_typestring
expires_ininteger

Errors

401
Unauthorized Error