Skip to content

Commit b33f542

Browse files
committed
update authentication api doc
1 parent 65a1e1f commit b33f542

File tree

4 files changed

+309
-47
lines changed

4 files changed

+309
-47
lines changed

account.md

+129-12
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,42 @@
44

55
Request body
66

7-
| KEY | EXAMPLE |
8-
| -------- | ------------------- |
9-
| username | kyon777 |
10-
| password | imjohnsmith777 |
11-
| email | [email protected] |
7+
| KEY | EXAMPLE |
8+
| -------------------- | ------------------------------------------------------------ |
9+
| username | kyon777 |
10+
| password | imjohnsmith777 |
11+
| email | [email protected] |
12+
| g-recaptcha-response | 03AJpayVF6YpF1BGU-kZqEwN6G2k7cOv16_Q-SvK8zOUHrtkqdlVrIf9BJhEnbecV7PwAgCSF1JKUC3Gr5AQILxBuSrKKZrvkHQlm2pZfnTFWuyq0rYID2oUhlsKxVA4FY03GEJV-BCaciZphPDZpvid9t9ompoh8HS0_iKP9EgD9ju7ksqSiy9XcVkHfOy7BQJ2qEeaR2qHxrG2wFLC6w0D4bG8dySX9VgKeMW_pvXnni9ZMLXIVcTz4WpDtaELvRaIc02wWjgmvZZ8DXJ0on2B7T1IACOFYu5dvDVRJz3DsRvs8nYIbz1MwRfzQGVycQz5p5Z8b1lwhkVotYlaetMS3A79ECfJPXOJs4_Hrd5q9TofiYOIbqFPk |
1213

1314
!> Password stored in the database was encrypted by [bcryptjs](https://github.com/dcodeIO/bcrypt.js), not the original password, feel free to use it.
1415

16+
Possible response
17+
18+
| code | message | note |
19+
| ------- | ------------------------------------------------------------ | ------ |
20+
| 1120001 | register successfully. | |
21+
| 1140001 | [username] is empty, please provide a correct one. | |
22+
| 1140002 | [username] must be at least 5 at most 15 characters long, please try another. | |
23+
| 1140003 | [password] is empty, please provide a correct one. | |
24+
| 1140004 | [password] must be at least 6 at most 17 characters long, please try another. | |
25+
| 1140005 | [email] is empty, please provide a correct one. | |
26+
| 1140006 | [email] is not in correct format, please try another. | |
27+
| 1940101 | Google reCAPTCHA verification failed. | common |
28+
| 1140901 | This username has been registered. | |
29+
| 1950301 | internal server error, database error. | common |
30+
1531
Example request
1632

1733
```bash
18-
curl -d "username=kyon777&password=imjohnsmith777&[email protected]" "https://animeloop.org/api/v2/auth/register"
34+
curl -d "username=kyon777&password=imjohnsmith777&[email protected]&g-recaptcha-response=03AJpayVF6YpF1BGU-kZqEwN6G2k7cOv16_Q-SvK8zOUHrtkqdlVrIf9BJhEnbecV7PwAgCSF1JKUC3Gr5AQILxBuSrKKZrvkHQlm2pZfnTFWuyq0rYID2oUhlsKxVA4FY03GEJV-BCaciZphPDZpvid9t9ompoh8HS0_iKP9EgD9ju7ksqSiy9XcVkHfOy7BQJ2qEeaR2qHxrG2wFLC6w0D4bG8dySX9VgKeMW_pvXnni9ZMLXIVcTz4WpDtaELvRaIc02wWjgmvZZ8DXJ0on2B7T1IACOFYu5dvDVRJz3DsRvs8nYIbz1MwRfzQGVycQz5p5Z8b1lwhkVotYlaetMS3A79ECfJPXOJs4_Hrd5q9TofiYOIbqFPk" "https://animeloop.org/api/v2/auth/register"
1935
```
2036

2137
Example response
2238

2339
```json
2440
{
2541
"status": "success",
26-
"code": 200,
42+
"code": 1120001,
2743
"message": "register successfully.",
2844
"data": {}
2945
}
@@ -42,6 +58,16 @@ Request body
4258

4359
?> When you sign up for an account, the system will automatically send an email to the email address you provided, so you do not need to call this interface manually.
4460

61+
Possible response
62+
63+
| code | message | note |
64+
| ------- | --------------------------------------- | ------ |
65+
| 1420002 | send verification email successfully. | |
66+
| 1420003 | this account has already been verified. | |
67+
| 1440003 | empty username or password. | |
68+
| 1440004 | incorrect username or password. | |
69+
| 1950301 | internal server error, database error. | common |
70+
4571
Example request
4672

4773
```bash
@@ -53,8 +79,8 @@ Example response
5379
```json
5480
{
5581
"status": "success",
56-
"code": 200,
57-
"message": "send email successfully.",
82+
"code": 1420002,
83+
"message": "send verification email successfully.",
5884
"data": {}
5985
}
6086
```
@@ -65,7 +91,14 @@ Example response
6591

6692
?> In the mailbox check the verification email with a verify url, You do not need to manually call this interface.
6793

68-
Example request
94+
| code | message | note |
95+
| ------- | ------------------------------------------------ | ------ |
96+
| 1420001 | verify account successfully. | |
97+
| 1440001 | [code] is empty, please provide a correct one. | |
98+
| 1440002 | [code] is invalid, please provide a correct one. | |
99+
| 1950301 | internal server error, database error. | common |
100+
101+
Example request
69102

70103
```bash
71104
curl https://animeloop.org/api/v2/auth/verify?code=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY3Rpb24iOiJ2ZXJpZnkiLCJ1c2VybmFtZSI6InNxaW5jdXJyeTIiLCJkYXRlIjoiMjAxOC0wMS0yN1QwNToyMDozMC40NjhaIn0.JZ8xpCqusaAw_swnHT4bKXfjyxBxfHz0HyBkmVVoe-A
@@ -76,8 +109,92 @@ Example response
76109
```json
77110
{
78111
"status": "success",
79-
"code": 200,
80-
"message": "send email successfully.",
112+
"code": 1420001,
113+
"message": "verify account successfully.",
81114
"data": {}
82115
}
83116
```
117+
118+
## login
119+
120+
**`POST /auth/login`**
121+
122+
Request body
123+
124+
| KEY | eXAMPLE |
125+
| -------------------- | ------------------------------------------------------------ |
126+
| username | kyon777 |
127+
| password | imjohnsmith777 |
128+
| g-recaptcha-response | 03AJpayVF6YpF1BGU-kZqEwN6G2k7cOv16_Q-SvK8zOUHrtkqdlVrIf9BJhEnbecV7PwAgCSF1JKUC3Gr5AQILxBuSrKKZrvkHQlm2pZfnTFWuyq0rYID2oUhlsKxVA4FY03GEJV-BCaciZphPDZpvid9t9ompoh8HS0_iKP9EgD9ju7ksqSiy9XcVkHfOy7BQJ2qEeaR2qHxrG2wFLC6w0D4bG8dySX9VgKeMW_pvXnni9ZMLXIVcTz4WpDtaELvRaIc02wWjgmvZZ8DXJ0on2B7T1IACOFYu5dvDVRJz3DsRvs8nYIbz1MwRfzQGVycQz5p5Z8b1lwhkVotYlaetMS3A79ECfJPXOJs4_Hrd5q9TofiYOIbqFPk |
129+
130+
!> The response of this request contains a session cookie.
131+
132+
Possible response
133+
134+
| code | message | note |
135+
| ------- | -------------------------------------- | ------ |
136+
| 1220001 | login successfully. | |
137+
| 1240101 | incorrect username or password. | |
138+
| 1240102 | this account has not yet verified. | |
139+
| 1940101 | Google reCAPTCHA verification failed. | common |
140+
| 1950301 | internal server error, database error. | common |
141+
142+
Example request
143+
144+
```bash
145+
curl -d "username=kyon777&password=imjohnsmith777&g-recaptcha-response=03AJpayVF6YpF1BGU-kZqEwN6G2k7cOv16_Q-SvK8zOUHrtkqdlVrIf9BJhEnbecV7PwAgCSF1JKUC3Gr5AQILxBuSrKKZrvkHQlm2pZfnTFWuyq0rYID2oUhlsKxVA4FY03GEJV-BCaciZphPDZpvid9t9ompoh8HS0_iKP9EgD9ju7ksqSiy9XcVkHfOy7BQJ2qEeaR2qHxrG2wFLC6w0D4bG8dySX9VgKeMW_pvXnni9ZMLXIVcTz4WpDtaELvRaIc02wWjgmvZZ8DXJ0on2B7T1IACOFYu5dvDVRJz3DsRvs8nYIbz1MwRfzQGVycQz5p5Z8b1lwhkVotYlaetMS3A79ECfJPXOJs4_Hrd5q9TofiYOIbqFPk" "https://animeloop.org/api/v2/auth/login"
146+
```
147+
148+
Example response
149+
150+
```json
151+
// response contains auth session cookie [animeloop.auth.sid=s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU]
152+
153+
{
154+
"status": "success",
155+
"code": 1220001,
156+
"message": "login successfully.",
157+
"data": {}
158+
}
159+
```
160+
161+
## Logout
162+
163+
**`POST /auth/logout`**
164+
165+
Request cookies
166+
167+
| KEY | EXAMPLE |
168+
| ------------------ | ------------------------------------------------------------ |
169+
| animeloop.auth.sid | s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU |
170+
171+
!> These requests have an empty body, authentication works with session cookie from login api.
172+
173+
Possible response
174+
175+
| code | message | note |
176+
| ------- | -------------------------------------- | ------ |
177+
| 1220002 | logout successfully. | |
178+
| 1940102 | cookie session validation failed. | common |
179+
| 1940103 | cookie session doesn't exist. | common |
180+
| 1950301 | internal server error, database error. | common |
181+
182+
Example request
183+
184+
```bash
185+
curl --cookie "animeloop.auth.sid=s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU" "https://animeloop.org/api/v2/auth/logout"
186+
```
187+
188+
Example response
189+
190+
```json
191+
// response contains auth session cookie [animeloop.auth.sid=s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU]
192+
193+
{
194+
"status": "success",
195+
"code": 1220002,
196+
"message": "logout successfully.",
197+
"data": {}
198+
}
199+
```
200+

token.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,39 @@
66

77
**`POST /auth/token/revoke`** Revoke the existing token
88

9-
Request body
9+
Request cookies
1010

11-
| KEY | EXAMPLE |
12-
| -------- | -------------- |
13-
| username | kyon777 |
14-
| password | imjohnsmith777 |
11+
| KEY | EXAMPLE |
12+
| ------------------ | ------------------------------------------------------------ |
13+
| animeloop.auth.sid | s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU |
14+
15+
!> These requests have an empty body, authentication works with session cookie from login api.
16+
17+
Possible response
18+
19+
| code | message | note |
20+
| ------- | ------------------------------------------ | ------ |
21+
| 1320001 | request token successfully. | |
22+
| 1320002 | request a new token successfully. | |
23+
| 1320003 | revoke the token successfully. | |
24+
| 1340401 | request token failed. token doesn't exist. | |
25+
| 1940102 | cookie session validation failed. | common |
26+
| 1940103 | cookie session doesn't exist. | common |
27+
| 1950301 | internal server error, database error. | common |
1528

1629
Example request
1730

1831
```bash
1932
# Get token
20-
curl -d "username=kyon777&password=imjohnsmith777" "https://animeloop.org/api/v2/auth/token"
33+
curl --cookie "animeloop.auth.sid=s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU" "https://animeloop.org/api/v2/auth/token"
2134
```
2235

2336
Example response
2437

2538
```json
2639
{
2740
"status":"success",
28-
"code":200,
41+
"code":1320001,
2942
"message":"request the token successfully.",
3043
"data": {
3144
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InNoaW5jdXJyeTIifQ.VMZHgDvyqeUHqN6Wg92CvlphdiwNynuOY5ELdFQTY3w"
@@ -39,15 +52,15 @@ Example request
3952

4053
```bash
4154
# Request a new token
42-
curl -d "username=kyon777&password=imjohnsmith777" "https://animeloop.org/api/v2/auth/token/new"
55+
curl --cookie "animeloop.auth.sid=s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU" "https://animeloop.org/api/v2/auth/token/new"
4356
```
4457

4558
Example response
4659

4760
```json
4861
{
4962
"status": "success",
50-
"code": 200,
63+
"code": 1320002,
5164
"message": "request a new token successfully.",
5265
"data": {
5366
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InNoaW5jdXJyeTIifQ.VMZHxDvyqeUHaN6Wg92CvlphvicNynuOY5ELdFQTY3w"
@@ -61,15 +74,15 @@ Example request
6174

6275
```bash
6376
# Revoke the existing token
64-
curl -d "username=kyon777&password=imjohnsmith777" "https://animeloop.org/api/v2/auth/token/revoke"
77+
curl --cookie "animeloop.auth.sid=s%3A4VtJUXAabKIew3Wib8scACX1lDZK6Z3d.7Hqy%2F8Nk8d0rFr4ygSCoEnwg5GD%2BVMfghQieThqQ2dU" "https://animeloop.org/api/v2/auth/token/revoke"
6578
```
6679

6780
Example response
6881

6982
```json
7083
{
7184
"status":"success",
72-
"code":200,
85+
"code":1320003,
7386
"message":"revoke the token successfully.",
7487
"data": {}
7588
}

0 commit comments

Comments
 (0)