Skip to content

Commit b7e227a

Browse files
authored
update restapi authorization (#1115)
1 parent 5fa1ad2 commit b7e227a

24 files changed

Lines changed: 984 additions & 482 deletions

src/UserGuide/Master/Table/API/RestAPI-V1_apache.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,57 @@ enable_rest_service=true
3131
```
3232

3333
## 2. Authentication
34+
35+
All RESTful APIs adopt **Basic Authentication**, except the health check interface `/ping`.
36+
All requests must carry the `Authorization` information in the request header.
3437

35-
Except for the health check endpoint `/ping`, the RESTful service uses basic authentication. Each URL request must include the header `'Authorization':'Basic' + base64.encode(username + ':' + password)`.
36-
37-
In the example, the username is `root` and the password is `root`. The corresponding Basic authentication header format is:
38-
39-
```Properties
40-
Authorization : Basic cm9vdDpyb290
38+
1. Authentication Format
4139
```
40+
Authorization: Basic <base64_string>
41+
```
42+
The `<base64_string>` is generated by directly Base64-encoding the string in the format `username:password`.
43+
Quick generation methods are shown below:
4244

43-
- If the username or password authentication fails, the following information is returned:
44-
45-
- HTTP status code: 801
45+
* Linux / macOS
46+
```bash
47+
echo -n "your_username:your_password" | base64
48+
eg: echo -n "root:root" | base64
49+
```
4650

47-
- Response body:
51+
* Windows
52+
```powershell
53+
# PowerShell
54+
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("username:password"))
55+
eg: [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("root:root"))
56+
```
57+
```cmd
58+
# CMD
59+
powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"username:password\"))"
60+
eg: powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"root:root\"))"
61+
```
4862

49-
```JSON
50-
{"code":801,"message":"WRONG_LOGIN_PASSWORD"}
51-
```
63+
2. Authentication Example
5264

53-
- If the `Authorization` header is not set, the following information is returned:
65+
Default username: `root`, password: `root`
5466

55-
- HTTP status code: 800
67+
- Concatenated string: `root:root`
68+
- Base64 encoded result: `cm9vdDpyb290`
69+
- Final Header:
70+
```
71+
Authorization: Basic cm9vdDpyb290
72+
```
5673

57-
- Response body:
74+
3. Error Description
75+
- Incorrect username or password: returns HTTP status code `801`
76+
```json
77+
{"code":801,"message":"WRONG_LOGIN_PASSWORD"}
78+
```
5879

59-
```JSON
60-
{"code":800,"message":"INIT_AUTH_ERROR"}
61-
```
80+
- Missing `Authorization` configuration: returns HTTP status code `800`
81+
```json
82+
{"code":800,"message":"INIT_AUTH_ERROR"}
83+
```
84+
6285

6386
## 3. Interface Definitions
6487

src/UserGuide/Master/Table/API/RestAPI-V1_timecho.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,56 @@ enable_rest_service=true
3434

3535
## 2. Authentication
3636

37-
Except for the health check endpoint `/ping`, the RESTful service uses basic authentication. Each URL request must include the header `'Authorization':'Basic' + base64.encode(username + ':' + password)`.
37+
All RESTful APIs adopt **Basic Authentication**, except the health check interface `/ping`.
38+
All requests must carry the `Authorization` information in the request header.
3839

39-
In the example, the username is `root` and the password is `root`. The corresponding Basic authentication header format is:
40-
41-
```Properties
42-
Authorization : Basic cm9vdDpyb290
40+
1. Authentication Format
4341
```
42+
Authorization: Basic <base64_string>
43+
```
44+
The `<base64_string>` is generated by directly Base64-encoding the string in the format `username:password`.
45+
Quick generation methods are shown below:
4446

45-
- If the username or password authentication fails, the following information is returned:
47+
* Linux / macOS
48+
```bash
49+
echo -n "your_username:your_password" | base64
50+
eg: echo -n "root:TimechoDB@2021" | base64
51+
```
4652

47-
- HTTP status code: 801
53+
* Windows
54+
```powershell
55+
# PowerShell
56+
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("username:password"))
57+
eg: [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("root:TimechoDB@2021"))
58+
```
59+
```cmd
60+
# CMD
61+
powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"username:password\"))"
62+
eg: powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"root:TimechoDB@2021\"))"
63+
```
4864

49-
- Response body:
65+
2. Authentication Example
5066

51-
```JSON
52-
{"code":801,"message":"WRONG_LOGIN_PASSWORD"}
53-
```
67+
Default username: `root`, password: `TimechoDB@2021`
5468

55-
- If the `Authorization` header is not set, the following information is returned:
69+
- Concatenated string: `root:TimechoDB@2021`
70+
- Base64 encoded result: `cm9vdDpUaW1lY2hvREJAMjAyMQ==`
71+
- Final Header:
72+
```
73+
Authorization: Basic cm9vdDpUaW1lY2hvREJAMjAyMQ==
74+
```
5675

57-
- HTTP status code: 800
76+
3. Error Description
77+
- Incorrect username or password: returns HTTP status code `801`
78+
```json
79+
{"code":801,"message":"WRONG_LOGIN_PASSWORD"}
80+
```
5881

59-
- Response body:
82+
- Missing `Authorization` configuration: returns HTTP status code `800`
83+
```json
84+
{"code":800,"message":"INIT_AUTH_ERROR"}
85+
```
6086

61-
```JSON
62-
{"code":800,"message":"INIT_AUTH_ERROR"}
63-
```
6487

6588
## 3. Interface Definitions
6689

src/UserGuide/Master/Tree/API/RestServiceV1_apache.md

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,56 @@ RESTful services are disabled by default.
3333
```
3434

3535
## 2. Authentication
36-
Except the liveness probe API `/ping`, RESTful services use the basic authentication. Each URL request needs to carry `'Authorization': 'Basic ' + base64.encode(username + ':' + password)`.
3736

38-
The username used in the following examples is: `root`, and password is: `root`.
37+
All RESTful services require **Basic authentication** except the health check interface `/ping`. An `Authorization` header must be carried in all requests.
3938

40-
And the authorization header is
39+
1. Authentication Format
40+
```
41+
Authorization: Basic <base64_string>
42+
```
43+
Where `<base64_string>` is the Base64 encoding result of the string formatted as `username:password`. Quick generation methods are as follows:
4144

45+
* Linux/macOS
46+
```bash
47+
echo -n "your_username:your_password" | base64
48+
Example: echo -n "root:root" | base64
4249
```
43-
Authorization: Basic cm9vdDpyb290
50+
51+
* Windows
52+
```powershell
53+
# PowerShell
54+
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("username:password"))
55+
Example: [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("root:root"))
4456
```
4557

46-
- If a user authorized with incorrect username or password, the following error is returned:
58+
```cmd
59+
# CMD
60+
powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"username:password\"))"
61+
Example: powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"root:root\"))"
62+
```
4763

48-
HTTP Status Code:`401`
64+
2. Authentication Example
4965

50-
HTTP response body:
51-
```json
52-
{
53-
"code": 600,
54-
"message": "WRONG_LOGIN_PASSWORD_ERROR"
55-
}
56-
```
66+
Default username: `root`, default password: `root`:
67+
- Concatenated string: `root:root`
68+
- Base64 encoded result: `cm9vdDpyb290`
69+
- Final Request Header:
70+
```
71+
Authorization: Basic cm9vdDpyb290
72+
```
73+
74+
3. Error Description
75+
- Incorrect username or password: Returns HTTP status code `600` with response content:
76+
```json
77+
{"code":600,"message":"WRONG_LOGIN_PASSWORD_ERROR"}
78+
```
5779

58-
- If the `Authorization` header is missing,the following error is returned:
80+
- Missing `Authorization` header: Returns HTTP status code `603` with response content:
81+
```json
82+
{"code":603,"message":"UNINITIALIZED_AUTH_ERROR"}
83+
```
5984

60-
HTTP Status Code:`401`
6185

62-
HTTP response body:
63-
```json
64-
{
65-
"code": 603,
66-
"message": "UNINITIALIZED_AUTH_ERROR"
67-
}
68-
```
6986

7087
## 3. Interface
7188

src/UserGuide/Master/Tree/API/RestServiceV1_timecho.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,53 @@ Note: As of version V2.0.8.2, the TimechoDB installation package does not includ
2626

2727
## 1. Enable RESTful Services
2828

29-
RESTful services are disabled by default.
29+
All RESTful services require **Basic authentication** except the health check interface `/ping`. An `Authorization` header must be carried in all requests.
3030

31-
Find the `conf/conf/iotdb-system.properties` file under the IoTDB installation directory and set `enable_rest_service` to `true` to enable the module.
31+
1. Authentication Format
32+
```
33+
Authorization: Basic <base64_string>
34+
```
35+
Where `<base64_string>` is the Base64 encoding result of the string formatted as `username:password`. Quick generation methods are as follows:
3236

33-
```properties
34-
enable_rest_service=true
35-
```
37+
* Linux/macOS
38+
```bash
39+
echo -n "your_username:your_password" | base64
40+
Example: echo -n "root:TimechoDB@2021" | base64
41+
```
3642

37-
## 2. Authentication
38-
Except the liveness probe API `/ping`, RESTful services use the basic authentication. Each URL request needs to carry `'Authorization': 'Basic ' + base64.encode(username + ':' + password)`.
43+
* Windows
44+
```powershell
45+
# PowerShell
46+
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("username:password"))
47+
Example: [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("root:TimechoDB@2021"))
48+
```
3949

40-
The username used in the following examples is: `root`, and password is: `TimechoDB@2021` //Before V2.0.6.x the default password is root.
50+
```cmd
51+
# CMD
52+
powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"username:password\"))"
53+
Example: powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"root:TimechoDB@2021\"))"
54+
```
4155

42-
And the authorization header is
56+
2. Authentication Example
4357

58+
Default username: `root`, default password: `TimechoDB@2021`:
59+
- Concatenated string: `root:TimechoDB@2021`
60+
- Base64 encoded result: `cm9vdDpUaW1lY2hvREJAMjAyMQ==`
61+
- Final Request Header:
4462
```
45-
Authorization: Basic cm9vdDpyb290
63+
Authorization: Basic cm9vdDpUaW1lY2hvREJAMjAyMQ==
4664
```
4765

48-
- If a user authorized with incorrect username or password, the following error is returned:
49-
50-
HTTP Status Code:`401`
51-
52-
HTTP response body:
53-
```json
54-
{
55-
"code": 600,
56-
"message": "WRONG_LOGIN_PASSWORD_ERROR"
57-
}
58-
```
59-
60-
- If the `Authorization` header is missing,the following error is returned:
61-
62-
HTTP Status Code:`401`
66+
3. Error Description
67+
- Incorrect username or password: Returns HTTP status code `600` with response content:
68+
```json
69+
{"code":600,"message":"WRONG_LOGIN_PASSWORD_ERROR"}
70+
```
6371

64-
HTTP response body:
65-
```json
66-
{
67-
"code": 603,
68-
"message": "UNINITIALIZED_AUTH_ERROR"
69-
}
70-
```
72+
- Missing `Authorization` header: Returns HTTP status code `603` with response content:
73+
```json
74+
{"code":603,"message":"UNINITIALIZED_AUTH_ERROR"}
75+
```
7176

7277
## 3. Interface
7378

src/UserGuide/Master/Tree/API/RestServiceV2_apache.md

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,55 @@ RESTful services are disabled by default.
3333
```
3434

3535
## 2. Authentication
36-
Except the liveness probe API `/ping`, RESTful services use the basic authentication. Each URL request needs to carry `'Authorization': 'Basic ' + base64.encode(username + ':' + password)`.
3736

38-
The username used in the following examples is: `root`, and password is: `root`.
37+
All RESTful services require **Basic authentication** except the health check interface `/ping`. An `Authorization` header must be carried in all requests.
3938

40-
And the authorization header is
39+
1. Authentication Format
40+
```
41+
Authorization: Basic <base64_string>
42+
```
43+
Where `<base64_string>` is the Base64 encoding result of the string formatted as `username:password`. Quick generation methods are as follows:
4144

45+
* Linux/macOS
46+
```bash
47+
echo -n "your_username:your_password" | base64
48+
Example: echo -n "root:root" | base64
4249
```
43-
Authorization: Basic cm9vdDpyb290
50+
51+
* Windows
52+
```powershell
53+
# PowerShell
54+
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("username:password"))
55+
Example: [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("root:root"))
4456
```
4557

46-
- If a user authorized with incorrect username or password, the following error is returned:
58+
```cmd
59+
# CMD
60+
powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"username:password\"))"
61+
Example: powershell "[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"root:root\"))"
62+
```
4763

48-
HTTP Status Code:`401`
64+
2. Authentication Example
4965

50-
HTTP response body:
51-
```json
52-
{
53-
"code": 600,
54-
"message": "WRONG_LOGIN_PASSWORD_ERROR"
55-
}
56-
```
66+
Default username: `root`, default password: `root`:
67+
- Concatenated string: `root:root`
68+
- Base64 encoded result: `cm9vdDpyb290`
69+
- Final Request Header:
70+
```
71+
Authorization: Basic cm9vdDpyb290
72+
```
5773

58-
- If the `Authorization` header is missing,the following error is returned:
74+
3. Error Description
75+
- Incorrect username or password: Returns HTTP status code `600` with response content:
76+
```json
77+
{"code":600,"message":"WRONG_LOGIN_PASSWORD_ERROR"}
78+
```
5979

60-
HTTP Status Code:`401`
80+
- Missing `Authorization` header: Returns HTTP status code `603` with response content:
81+
```json
82+
{"code":603,"message":"UNINITIALIZED_AUTH_ERROR"}
83+
```
6184

62-
HTTP response body:
63-
```json
64-
{
65-
"code": 603,
66-
"message": "UNINITIALIZED_AUTH_ERROR"
67-
}
68-
```
6985

7086
## 3. Interface
7187

0 commit comments

Comments
 (0)