-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.yaml
596 lines (580 loc) · 17.8 KB
/
api.yaml
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
openapi: '3.0.3'
info:
version: '1.0.11'
title: Netsoc IAM
description: |
API for managing and authenticating Netsoc users.
servers:
- url: https://iam.netsoc.ie/v1
- url: https://iam.staging.netsoc.ie/v1
- url: http://localhost:8080/v1
components:
securitySchemes:
jwt:
type: http
scheme: bearer
bearerFormat: jwt
description: Any user JWT (including non-admin and expired)
jwt_admin:
type: http
scheme: bearer
bearerFormat: jwt
description: Valid admin JWT
jwt_verify:
type: http
scheme: bearer
bearerFormat: jwt
description: Email verification token
jwt_reset:
type: http
scheme: bearer
bearerFormat: jwt
description: Password reset token
parameters:
UserID:
name: uid
in: path
required: true
schema:
$ref: '#/components/schemas/UserID'
description: User ID
Username:
name: username
in: path
required: true
schema:
type: string
description: User's username.
example: root
UsernameOrSelf:
name: username
in: path
required: true
schema:
type: string
description: |
User's username. Can be `self` to indicate the currently authenticated user.
example: root
responses:
InternalError:
description: General server error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
NotFoundError:
description: User with username does not exist
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
ValidationError:
description: Validation error (e.g. Required field missing)
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
ConflictError:
description: User with username / email already exists
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
AuthError:
description: Authorization error (e.g. incorret password, invalid token, token expired etc.)
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
AdminError:
description: Admin token is required
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
schemas:
Error:
type: object
required:
- message
properties:
message:
type: string
description: Message explaining the error
UserID:
type: integer
format: int32
description: Unique database identifier, not modifiable.
example: 1
UserMeta:
type: object
required:
- created
- updated
description: Metadata about the user, not modifiable.
properties:
created:
type: string
format: date-time
description: Date and time at which the user was created
example: '2020-09-16T16:05:25.911242339Z'
updated:
type: string
format: date-time
description: Date and time at which the user was last updated
example: '2020-09-16T16:05:25.911242339Z'
User:
type: object
required:
- id
- email
- username
- first_name
- last_name
properties:
id:
$ref: '#/components/schemas/UserID'
username:
type: string
description: Unique username (must be a valid DNS name)
example: brodude
email:
type: string
pattern: ^\S+@tcd\.ie$
description: Unique email address (must be `@tcd.ie`)
example: [email protected]
password:
type: string
nullable: true
minLength: 8
description: |
Stored internally as a bcrypt hash. If unset, login will be disabled.
example: hunter22
first_name:
type: string
example: Bro
last_name:
type: string
example: Dude
ssh_key:
type: string
nullable: true
description: SSH public key
example: |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+kCHXqtznkT9IBN5WxZHmXI97k3BumT+N4lyHWMo0pykpACCOcGw52EXxQveNqgcwcRUgamL9A2JTE//WRf3O4nBofeTRNKcRxTjRoUVIt/F0xbf09yWBqJOXZ8rqLkXhRvSpr1TCUZtYVp5iLtpERp622OMIqHSwa6HlxBqsCFkBeq1bRyNtYK/IaQAuBPW9MNeFriGqA0Vq078ccXp+JINxJbr+ZJybVg6PVqnMD+PgGMZQLkoWjwjH3vcJZZt584UPtrXKpNZuKy6dcMCb2U+O9NOaO66168sBVuK0kZHh51nJ7ZH38VLGiBipRgIQ1fzic3Ncn6GC9ko3/OwT
verified:
type: boolean
nullable: true
default: false
description: Indicates if the user's email address is verified. Only modifiable directly by an admin.
is_admin:
type: boolean
nullable: true
default: false
description: Indicates if the user is an admin. Only modifiable by an admin.
renewed:
type: string
format: date-time
description: |
Date and time when the user's membership was last renewed. Only modifiable by an admin.
default: '0001-01-01T00:00:00Z'
meta:
$ref: '#/components/schemas/UserMeta'
LoginRequest:
type: object
required:
- password
properties:
password:
type: string
example: hunter22
ResetPasswordRequest:
type: object
properties:
password:
type: string
example: hunter22
IssueTokenRequest:
type: object
properties:
duration:
type: string
description: |
Duration of validity for token. Follows [Go's `time.Duration` format](https://pkg.go.dev/time#ParseDuration)
example: '876000h'
TokenResponse:
type: object
properties:
token:
type: string
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzE4MjAxNDcuNjk1OTI0LCJpYXQiOjE2MDAyODc1MTkuODQ4ODk1LCJpc3MiOiJpYW1kIiwibmJmIjoxNjAwMjg3NTE5Ljg0ODg5Nywic3ViIjoiOTAiLCJpc19hZG1pbiI6dHJ1ZSwidmVyc2lvbiI6MX0.M-omIcb7XI9o44_ts6klxFIhNyf4d8kmztMpUxvdKXQ'
paths:
/users:
get:
summary: List users
operationId: getUsers
tags: [users]
security:
- jwt_admin: []
responses:
'200':
description: An array of users
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'500':
$ref: '#/components/responses/InternalError'
post:
summary: Create a new user
operationId: createUser
tags: [users]
security:
- {}
- jwt_admin: []
description: |
A verification email will automatically be sent to the user's email address.
Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an
email with a link to the configured UI service and the token.
requestBody:
required: true
description: User to create
content:
application/json:
schema:
$ref: '#/components/schemas/User'
examples:
registration:
summary: User self-registration
value:
username: bro
email: [email protected]
password: hunter22
first_name: Bro
last_name: Dude
admin:
summary: Admin user
value:
username: admin
email: [email protected]
password: hunter22
first_name: Admin
last_name: Dude
is_admin: true
responses:
'201':
description: New user
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
$ref: '#/components/responses/ValidationError'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'409':
$ref: '#/components/responses/ConflictError'
'500':
$ref: '#/components/responses/InternalError'
/users/id:{uid}:
get:
summary: Get a user by their ID
operationId: getUserByID
tags: [users]
parameters:
- $ref: '#/components/parameters/UserID'
security:
- jwt_admin: []
description: |
Requires a valid admin JWT.
responses:
'200':
description: Requested user
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
/users/{username}:
get:
summary: Get a user by their username
operationId: getUser
tags: [users]
parameters:
- $ref: '#/components/parameters/UsernameOrSelf'
security:
- jwt: []
- jwt_admin: []
description: |
Requires at least an expired user JWT. A valid admin JWT is required to retrieve a user other than `self`.
responses:
'200':
description: Requested user
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
delete:
summary: Delete a user by their username
operationId: deleteUser
tags: [users]
parameters:
- $ref: '#/components/parameters/UsernameOrSelf'
security:
- jwt: []
- jwt_admin: []
description: |
Requires at least an expired user JWT. A valid admin JWT is required to delete a user other than `self`.
responses:
'200':
description: Deleted user
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
patch:
summary: Update a user by their username
operationId: updateUser
tags: [users]
parameters:
- $ref: '#/components/parameters/UsernameOrSelf'
security:
- jwt: []
- jwt_admin: []
description: |
Requires at least an expired user JWT. A valid admin JWT is required to update admin-only
fields and modify a user other than `self`.
A verification email will automatically be sent to the user's email address if it has been changed.
Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an
email with a link to the configured UI service and the token.
requestBody:
required: true
description: Partial user containing fields to update
content:
application/json:
schema:
$ref: '#/components/schemas/User'
examples:
profile:
summary: User self-profile update
value:
last_name: ExtraDude
password: password
admin:
summary: Admin-only
value:
verified: true
renewed: '2100-01-01T00:00:00Z'
is_admin: true
responses:
'200':
description: User with un-updated values
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
$ref: '#/components/responses/ValidationError'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'404':
$ref: '#/components/responses/NotFoundError'
'409':
$ref: '#/components/responses/ConflictError'
'500':
$ref: '#/components/responses/InternalError'
/users/{username}/login:
post:
summary: Log into a user account (obtain JWT)
operationId: login
tags: [users]
parameters:
- $ref: '#/components/parameters/Username'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/LoginRequest'
responses:
'200':
description: Login token
content:
application/json:
schema:
$ref: '#/components/schemas/TokenResponse'
'401':
$ref: '#/components/responses/AuthError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
delete:
summary: |
Log out of a user account (invalidate existing JWT's)
operationId: logout
tags: [users]
parameters:
- $ref: '#/components/parameters/UsernameOrSelf'
security:
- jwt: []
- jwt_admin: []
description: |
Requires at least an expired user JWT. A valid admin JWT is required to logout a user
other than `self`.
responses:
'204':
description: No content
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
patch:
summary: Verify email address
operationId: verify
tags: [users]
parameters:
- $ref: '#/components/parameters/UsernameOrSelf'
security:
- jwt_verify: []
- {}
description: |
Making a request without a token will generate a token and send it to the user's email address.
Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an
email with a link to the configured UI service and the token. Passing the returned token to this
endpoint will perform the verification.
responses:
'204':
description: No content
'400':
$ref: '#/components/responses/ValidationError'
'401':
$ref: '#/components/responses/AuthError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
put:
summary: Reset password
operationId: resetPassword
tags: [users]
parameters:
- $ref: '#/components/parameters/UsernameOrSelf'
security:
- jwt_reset: []
- {}
description: |
Making a request without a token (or request body) will generate a token and send it to the
user's email address.
Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an
email with a link to the configured UI service and the token. Passing the returned token to this
endpoint (along with the new password) will perform the reset.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ResetPasswordRequest'
responses:
'204':
description: No content
'400':
$ref: '#/components/responses/ValidationError'
'401':
$ref: '#/components/responses/AuthError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'
/users/self/token:
get:
summary: Validate a token
operationId: validateToken
tags: [users]
security:
- jwt: []
- jwt_admin: []
responses:
'204':
description: Token is valid
'401':
$ref: '#/components/responses/AuthError'
'500':
$ref: '#/components/responses/InternalError'
/users/{username}/token:
post:
summary: Issue a token
operationId: issueToken
tags: [users]
parameters:
- $ref: '#/components/parameters/Username'
security:
- jwt_admin: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/IssueTokenRequest'
examples:
infinity:
summary: Near-infinite duration
value:
duration: '876000h'
short:
summary: (Very) short duration
value:
duration: '30s'
responses:
'200':
description: Issued token
content:
application/json:
schema:
$ref: '#/components/schemas/TokenResponse'
'400':
$ref: '#/components/responses/ValidationError'
'401':
$ref: '#/components/responses/AuthError'
'403':
$ref: '#/components/responses/AdminError'
'404':
$ref: '#/components/responses/NotFoundError'
'500':
$ref: '#/components/responses/InternalError'