refactor(auth): move authentication params to headers and simplify validation

- Move token and timestamp validation to HTTP headers
- Simplify ValidateTimeStamp to return boolean
- Update AddUser to use default "visitor" type
- Remove redundant timestamp and token fields from request structs
- Update API documentation to reflect header-based authentication
This commit is contained in:
2026-02-28 15:32:32 +08:00
parent aa70e7c0f0
commit b661118180
6 changed files with 113 additions and 134 deletions
+50 -20
View File
@@ -69,7 +69,8 @@ All API responses are returned in JSON format:
```
**Important Notes:**
- For **POST** requests: All data is sent in the request body as JSON
- For all requests: Authentication token and timestamp are sent in HTTP headers (prefixed with `X-`)
- For **POST** requests: Other data is sent in the request body as JSON
- For **GET** requests: All data is sent in HTTP headers (prefixed with `X-`)
- All requests require authentication (except `/register` and `/login`)
- Timestamps are in milliseconds (Unix timestamp)
@@ -82,21 +83,28 @@ All API responses are returned in JSON format:
**Method:** POST
**Content-Type:** application/json
**Request:**
**Request Headers:**
```
X-Timestamp: 1704067200000
```
**Request Body:**
```json
{
"username": "your_username",
"passwd": "YourPass123!",
"timeStamp": 1704067200000,
"type": "admin"
}
```
| Header | Type | Required | Description |
|--------|------|----------|-------------|
| X-Timestamp | int64 | Yes | Client timestamp in milliseconds |
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| username | string | Yes | Username (no special characters) |
| passwd | string | Yes | Password (must contain uppercase, lowercase, digit, and special character, min 8 chars) |
| timeStamp | int64 | Yes | Client timestamp in milliseconds |
| type | string | No | User type: superuser, admin, visitor (default: visitor) |
**Response:**
@@ -120,20 +128,27 @@ All API responses are returned in JSON format:
**Method:** POST
**Content-Type:** application/json
**Request:**
**Request Headers:**
```
X-Timestamp: 1704067200000
```
**Request Body:**
```json
{
"username": "your_username",
"passwd": "YourPass123!",
"timeStamp": 1704067200000
"passwd": "YourPass123!"
}
```
| Header | Type | Required | Description |
|--------|------|----------|-------------|
| X-Timestamp | int64 | Yes | Client timestamp in milliseconds |
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| username | string | Yes | Username |
| passwd | string | Yes | Password |
| timeStamp | int64 | Yes | Client timestamp in milliseconds |
**Response:**
```json
@@ -158,11 +173,15 @@ All API responses are returned in JSON format:
**Content-Type:** application/json
**Auth Required:** Yes (token)
**Request:**
**Request Headers:**
```
X-Token: your_token
X-Timestamp: 1704067200000
```
**Request Body:**
```json
{
"token": "your_token",
"timeStamp": 1704067200000,
"instanceInfo": {
"name": "my_frpc",
"serverAddr": "127.0.0.1",
@@ -177,10 +196,13 @@ All API responses are returned in JSON format:
}
```
| Header | Type | Required | Description |
|--------|------|----------|-------------|
| X-Token | string | Yes | Authentication token |
| X-Timestamp | int64 | Yes | Client timestamp in milliseconds |
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| token | string | Yes | Authentication token |
| timeStamp | int64 | Yes | Client timestamp in milliseconds |
| instanceInfo.name | string | Yes | Instance name |
| instanceInfo.serverAddr | string | Yes | frps server address |
| instanceInfo.serverPort | string | Yes | frps server port |
@@ -211,12 +233,16 @@ All API responses are returned in JSON format:
**Content-Type:** application/json
**Auth Required:** Yes (token)
**Request:**
**Request Headers:**
```
X-Token: your_token
X-Timestamp: 1704067200000
```
**Request Body:**
```json
{
"instanceName": "my_frpc",
"token": "your_token",
"timeStamp": 1704067200000
"instanceName": "my_frpc"
}
```
@@ -242,12 +268,16 @@ All API responses are returned in JSON format:
You can modify multiple fields at once:
**Request:**
**Request Headers:**
```
X-Token: your_token
X-Timestamp: 1704067200000
```
**Request Body:**
```json
{
"instanceName": "my_frpc",
"token": "your_token",
"timeStamp": 1704067200000,
"name": "new_name",
"serverAddr": "192.168.1.1",
"serverPort": "7000",