-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.json
More file actions
320 lines (320 loc) · 10.3 KB
/
openapi.json
File metadata and controls
320 lines (320 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
{
"openapi": "3.0.0",
"info": {
"title": "Secure OTP Server",
"version": "1.0.0"
},
"paths": {
"/health": {
"get": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
},
"post": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
},
"put": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
},
"delete": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
},
"patch": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
},
"head": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
},
"options": {
"summary": "Check health status",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/otp/create": {
"post": {
"operationId": "createOtp",
"summary": "Create or reuse an OTP token",
"description": "Validates the credential payload, issues a new OTP if necessary, and sets a fresh session cookie.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"description": "Credential payload to verify before generating an OTP. Customize `src/custom/credential.ts` to tighten this schema.",
"oneOf": [
{ "type": "object", "additionalProperties": true },
{ "type": "array", "items": {} },
{ "type": "string", "minLength": 1 },
{ "type": "number" }
]
},
"examples": {
"objectCredential": { "value": { "email": "user@example.com" } },
"stringCredential": { "value": "internal-user-id-123" }
}
}
}
},
"responses": {
"200": {
"description": "OTP session metadata.",
"headers": {
"Set-Cookie": {
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/OtpSessionState" }
}
}
},
"400": {
"description": "Invalid credential payload or malformed/expired cookie.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
"examples": {
"credentialInvalid": { "$ref": "#/components/examples/ErrCredentialInvalid" },
"otpInvalidCookie": { "$ref": "#/components/examples/ErrOtpInvalidCookie" }
}
}
}
},
"413": { "$ref": "#/components/responses/ErrBodyTooLarge" },
"429": { "$ref": "#/components/responses/ErrOtpTooManyRequests" },
"500": { "$ref": "#/components/responses/ErrServer" }
}
}
},
"/api/otp/resend": {
"post": {
"operationId": "resendOtp",
"summary": "Resend current OTP if allowed",
"responses": {
"200": {
"description": "Updated session metadata after resending.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/OtpSessionState" }
}
}
},
"400": {
"description": "Resend not allowed (blocked or expired) or cookie invalid.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
"examples": {
"otpResendNotAllowed": { "$ref": "#/components/examples/ErrOtpResendNotAllowed" },
"otpInvalidCookie": { "$ref": "#/components/examples/ErrOtpInvalidCookie" }
}
}
}
},
"429": { "$ref": "#/components/responses/ErrOtpTooManyRequests" },
"500": { "$ref": "#/components/responses/ErrServer" }
}
}
},
"/api/otp/verify": {
"post": {
"operationId": "verifyOtp",
"summary": "Verify an OTP value",
"requestBody": {
"required": true,
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"required": ["otp"],
"properties": {
"otp": {
"type": "string",
"minLength": 8,
"maxLength": 8,
"pattern": "^\\w+$",
"description": "OTP value generated in the current session (default length: 8, regex: /\\w+/)."
}
}
},
"examples": {
"default": {
"value": {
"otp": "1ab34cd5"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OTP verified and final action executed."
},
"400": {
"description": "OTP incorrect, blocked, or cookie invalid.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
"examples": {
"otpIncorrect": { "$ref": "#/components/examples/ErrOtpIncorrect" },
"otpTooManyAttempts": { "$ref": "#/components/examples/ErrOtpTooManyAttempts" },
"otpInvalidFormat": { "$ref": "#/components/examples/ErrOtpInvalidFormat" },
"otpInvalidCookie": { "$ref": "#/components/examples/ErrOtpInvalidCookie" },
"otpExpired": { "$ref": "#/components/examples/ErrOtpExpired" }
}
}
}
},
"413": { "$ref": "#/components/responses/ErrBodyTooLarge" },
"429": { "$ref": "#/components/responses/ErrOtpTooManyRequests" },
"500": { "$ref": "#/components/responses/ErrServer" }
}
}
}
},
"components": {
"schemas": {
"OtpSessionState": {
"type": "object",
"description": "Current OTP credential state associated with the encrypted cookie payload.",
"properties": {
"expires": {
"type": "string",
"format": "date-time",
"description": "When the current OTP becomes invalid (time precision reduced server-side)."
},
"blocked": {
"type": "boolean",
"description": "True once attempts are exhausted; prevents further verification."
},
"resendBlock": {
"type": "string",
"format": "date-time",
"description": "Earliest time when another resend is allowed."
},
"otpBlock": {
"type": "string",
"format": "date-time",
"description": "Temporary block applied after repeated invalid attempts."
}
},
"required": ["expires"]
},
"ErrorResponse": {
"type": "object",
"properties": {
"error": { "type": "string" },
"message": { "type": "string" }
},
"required": ["error"]
}
},
"responses": {
"ErrBodyTooLarge": {
"description": "Request payload exceeded 100 KiB limit.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
"examples": {
"default": { "$ref": "#/components/examples/ErrBodyTooLarge" }
}
}
}
},
"ErrOtpTooManyRequests": {
"description": "Too many OTP operations in a short time window.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
"examples": {
"default": { "$ref": "#/components/examples/ErrOtpTooManyRequests" }
}
}
}
},
"ErrServer": {
"description": "Unhandled server error.",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
"examples": {
"default": { "$ref": "#/components/examples/ErrServer" }
}
}
}
}
},
"examples": {
"ErrBodyTooLarge": {
"value": { "error": "BODY:TOO_LARGE", "message": "The body of your request is too large." }
},
"ErrCredentialInvalid": {
"value": { "error": "CREDENTIAL:INVALID", "message": "Invalid credential." }
},
"ErrOtpExpired": {
"value": { "error": "OTP:EXPIRED", "message": "The current OTP is expired. Please request a new code." }
},
"ErrOtpIncorrect": {
"value": { "error": "OTP:INCORRECT", "message": "Incorrect OTP value." }
},
"ErrOtpInvalidCookie": {
"value": { "error": "OTP:INVALID_COOKIE", "message": "The OTP cookies are invalid." }
},
"ErrOtpInvalidFormat": {
"value": { "error": "OTP:INVALID_FORMAT", "message": "Invalid OTP format." }
},
"ErrOtpResendNotAllowed": {
"value": { "error": "OTP:RESENT_NOT_ALLOWED", "message": "Resend not allowed." }
},
"ErrOtpTooManyAttempts": {
"value": {
"error": "OTP:TOO_MANY_ATTEMPTS",
"message": "Too many attempts. For security reasons, the OTP has been blocked. Please wait for it to expire and then try again."
}
},
"ErrOtpTooManyRequests": {
"value": { "error": "OTP:TOO_MANY_REQUESTS", "message": "Too many requests, slow down :)" }
},
"ErrServer": {
"value": { "error": "SERVER", "message": "The server has some issues, it's not your fault." }
}
}
}
}