-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapiary.apib
More file actions
522 lines (282 loc) · 12.5 KB
/
apiary.apib
File metadata and controls
522 lines (282 loc) · 12.5 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
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
FORMAT: 1A
HOST: https://api.getlockbox.com
# Lockbox
Lockbox is a dead simple, centralized and secured storage for your credentials.
Below is presented the API documentation that will let you use Lockbox within any application that can perform HTTP requests.
## Initialization [/init]
### Initialize lockbox [POST]
When you run Lockbox for the first time, it is required to initialize the server with a new admin account.
Initialization can be performed only once and it returns an API key that can be used for performing any operation like adding new entries or users.
From that point, you must include <em>Authorization: Bearer API_KEY</em> for each request.
+ Request (application/json)
{
"username": "root", "password": "secret"
}
+ Response 200 (application/json)
{
"apiKey": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJTdWIiOiJhZG1pbiIsIkV4cCI6NjY3NjkxODY4NDI3MzA5MTYwfQ.DfwQx4LHNwQqWsaZEStfOzQC-eQKxbsBOZjm5bMeaX18j3Nu1tby9oYQ2IybzCdCP7XvJfaGHOV1rJQT5xEJXQ"
}
## API keys [/api-keys]
### Create a new API key [POST]
Generates an additional API key for the user. <em>Expiry</em> is an additional parameter used for setting the date after which the key will be no longer available - by default it never expires.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Body
{"expiry": "10:12:10:00"}
+ Response 200 (application/json)
{
"apiKey": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJTdWIiOiJhZG1pbiIsIkV4cCI6NjY3NjkxODY4NDI3MzA5MTYwfQ.DfwQx4LHNwQqWsaZEStfOzQC-eQKxbsBOZjm5bMeaX18j3Nu1tby9oYQ2IybzCdCP7XvJfaGHOV1rJQT5xEJXQ"
}
## API key [/api-keys/{apiKey}]
### Delete API key [DELETE]
Removes API key from the system, so it can no longer be used for authentication purposes.
User must have at least one API key assigned - if you will try to remove the last remaining one API key, the operation will fail.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 204 (application/json)
## Authentication [/authenticate]
### Authenticate [POST]
Authenticates the user if the provided credentials are valid. Return an object containing authentication token and it's expiry (by default 7 days) as a ticks using epoch format.
+ Request (application/json)
+ Body
{"username": "user1", "password": "secret"}
+ Response 200 (application/json)
{
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJTdWIiOiJhZG1pbiIsIkV4cCI6NjY3NjkxODY4NDI3MzA5MTYwfQ.DfwQx4LHNwQqWsaZEStfOzQC-eQKxbsBOZjm5bMeaX18j3Nu1tby9oYQ2IybzCdCP7XvJfaGHOV1rJQT5xEJXQ",
"expiry": 1234567890
}
## Boxes [/boxes]
Box is a kind of workspace to which you can assign one or more users and add entries that hold the encrypted values.
### Browse boxes [GET]
List all boxes names to which the user belongs.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
["default"]
## Box [/boxes/{box}]
### Create a new box [POST]
Creates a new box with a single user being a box owner and an empty collection of entries.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 201
+ Headers
Location: /boxes/{name}
### Get box [GET]
Returns details about the box.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
{
"name": "default",
"owner": "root",
"createdAt": "2016-11-02 18:56:12",
"updatedAt": "2016-11-02 18:56:52",
"entries": [
"appsettings"
],
"users": [
{
"username": "root",
"role": "boxadmin",
"isActive": true
},
{
"username": "user1",
"role": "boxuser",
"isActive": true
}
]
}
### Delete box [DELETE]
Removes box from the system including all of the entries.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 204
## Box users [/boxes/{box}/users]
The box may contain one or more users with different roles (<em>boxuser</em>, <em>boxadmin</em>) and permissions.
Required role: <strong>boxadmin</strong>
### Browse box users [GET]
Returns list of usernames that are assigned to the box.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
[
"root",
"user1"
]
### Add user to box [POST]
Adds existing user in the system to the selected box with default permissions <em>["ReadEntryKeys", "ReadEntry"]</em>.
You may also include an optional parameter <em>Role</em> (<em>boxuser</em>, <em>boxadmin</em>) - if not specified the default <em>boxuser</em> role will be assigned.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Body
{"username": "user1", "role": "boxuser"}
+ Response 201
+ Headers
Location: /boxes/default/users/user1
## Box user [/boxes/{box}/users/{username}]
All operations require the user role of <strong>boxadmin</strong> in order to be performed.
The only exception is fetching the box user details - if the given username does match with the user that performs the request, the request will succeed.
### Get box user details [GET]
Returns details about the user in the box.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
{
"username": "user1",
"role": "boxuser",
"isActive": true,
"permissions": [
"readentrykeys",
"readentry"
]
}
### Update box user [PUT]
Updates the user in the box. All of the parameters are optional (nullable).
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Body
{
"role": "boxadmin",
"isActive": false
}
+ Response 204 (application/json)
### Delete box user [DELETE]
Removes user account from the box.
Box must have at least one user with <em>boxadmin</em> role assigned - if you will try to remove the last remaining <em>boxadmin</em>, the operation will fail.
It is also not possible to remove the owner of the box.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 204
## Box user permissions [/boxes/{box}/users/{username}/permissions]
Permissions are a way to restrict an access to the particular resources and operations for the selected users in box.
All operations require the user role of <strong>boxadmin</strong> in order to be performed.
The only exception is fetching the box user permissions - if the given username does match with the user that performs the request, the request will succeed.
### Get box user permissions [GET]
Returns a list of permissions assigned to the selected user in box.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
["readEntryKeys", "readEntry", "createEntry", "deleteEntry"]
### Update box user permissions [PUT]
Updates user permissions specified in the request body (removes all of the already set permissions and sets the new ones). If the permissions will not be specified it will simply remove all user permissions.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Body
["readEntryKeys", "readEntry", "createEntry", "deleteEntry"]
+ Response 204
### Delete box user permissions [DELETE]
Removes all permissions assigned to the given user.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 204
## Entries [/boxes/{box}/entries]
Entries are what the Lockbox is all about - entry is an object that has its unique key, encrypted value (can be anything e.g. object, string or number).
Each entry may be encrypted with a different encryption key. The Lockbox server does not store the keys anywhere, which means that even if the database was compromised an attacker will not be able to decrypt the values.
In order to decrypt/encrypt an entry, you have to include a header <em>X-Encryption-Key</em> containing your custom encryption key used for entry encryption.
If an entry already exists for the given key, it will be updated with the new value.
### Create a new entry [POST]
Creates a new entry that will be safely stored (with encrypted value using custom encryption key specified by the user) in the database.
Required permission: <strong>CreateEntry</strong>
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
X-Encryption-Key: ENCRYPTION_KEY
+ Body
{"key": "my-entry", "value": {"email": "my@email.com", "password": "secret"}}
+ Response 201
+ Headers
Location: /entries/my-entry
### Browse entries [GET]
List all entries (keys) available in the system.
Required permission: <strong>ReadEntryKeys</strong>
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
["my-entry"]
## Entry [/boxes/{box}/entries/{key}]
### Get entry [GET]
Returns decrypted entry value.
Required permission: <strong>ReadEntry</strong>
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
X-Encryption-Key: ENCRYPTION_KEY
+ Response 200 (application/json)
{
"email": "my@email.com",
"password": "secret"
}
### Delete entry [DELETE]
Removes entry from the system.
Required permission: <strong>DeleteEntry</strong>
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 204
## Users [/users]
It is considered a good practice to use a separate user accounts with different permissions for unique applications.
You can also skip this part and use the root API key directly (from admin account).
All operations require the user role of <strong>admin</strong> in order to be performed unless the application setting: <em>requireAdminToCreateUser</em> is set to <em>false</em>.
### Create a new user [POST]
Create a new user with a single API key being returned within a <strong>X-API-Key</strong> header.
You may also include an optional parameter <em>Role</em> (user, admin) - if not specified the default user role will be assigned.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Body
{"username": "user1", "password": "secret", "role": "user"}
+ Response 201
+ Headers
X-API-Key: API_KEY
Location: /users/user1
### Browse users [GET]
List all usernames available in the system.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
["admin", "user1"]
## User [/users/{username}]
All operations require the user role of <strong>admin</strong> in order to be performed.
The only exception is fetching the user deatils - if the given username does match with the user that performs the request, the request will succeed.
### Get user details [GET]
Returns details about the user account including available API keys.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 200 (application/json)
{
"username": "user1",
"role": "user",
"isActive": true,
"apiKeys": [
"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJTdWIiOiJ1c2VyMSIsIkV4cCI6NjY3NjkxODc0NDk5MzE3MTkwfQ.y4PLZzhDK65qd6mU1x3m7ass1fuE1AGJhhyN-96DuaqtWCOeRzd8gppM62Pdemp3e69DefmZQtwammerTTegmw"
],
"permissions": [
"readEntryKeys",
"readEntry"
]
}
### Delete user [DELETE]
Removes user account from the system.
System must have at least one user with admin role assigned - if you will try to remove the last remaining administrator, the operation will fail.
+ Request (application/json)
+ Headers
Authorization: Bearer API_KEY
+ Response 204