-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapiary.apib
380 lines (276 loc) · 9.2 KB
/
apiary.apib
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
FORMAT: 1A
HOST: http://auth:3000/
# >_ secret_tech AUTH Service
Auth is a service that manages JWT-authentication, it's main responsibilities are:
1. Tenants management.
2. Users management.
3. Generation of JWT tokens.
4. Validation of JWT tokens.
Common workflow is following:
1. Register a tenant. Tenant is expected to be a service which requires authentication.
2. Login tenant. Save received token. Use this token further to manage your tenant's users. Make sure that your end users DO NOT have access to this token!
3. Create a user when he registers at your service.
4. Login the user when he logins at your service, save received token on user's side (Browser local storage, etc.).
5. Verify saved token whenever authentication required.
6. Logout the user when necessary.
7. Delete the user when his account is not active anymore or deleted.
8. Logout your tenant's session when you stop using your service or need to deactivate tenant token for some reason.
# Group Tenant
## Register tenant [/tenant]
### Register new tenant [POST]
+ email `test@test.com` (string, required, email)
+ password `passwordA6` (string, required, min: 6, regex: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,}$)
+ Request (application/json)
{
"email": "test@test.com",
"password": "passwordA6"
}
+ Response 200 (application/json)
{
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"email": "test@test.com",
"token": "jwt_token"
}
## Login tenant to create new JWT token [/tenant/login]
### Login tenant [POST]
+ email `test@test.com` (string, required, email)
+ password `passwordA6` (string, required, min: 6, regex: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,}$)
+ Request (application/json)
{
"email": "test@test.com",
"password": "password"
}
+ Response 200 (application/json)
{
"token": "jwt_token"
}
## Logout tenant to invalidate JWT token [/tenant/logout]
### Logout tenant [POST]
+ accessToken `jwt` (string, required)
+ Request (application/json)
{
"token": "jwt_token"
}
+ Response 200 (application/json)
{
"result": 1
}
## Verify tenant's JWT token [/tenant/verify]
### Verify tenant's token [POST]
+ token `jwt` (string, required)
+ Request (application/json)
{
"token": "jwt_token"
}
+ Response 200 (application/json)
{
"decoded": {
"id": "24d22df4-5709-4506-a974-646d78b519fb",
"login": "tenant:companies@jincor.com",
"jti": "24d22df4-5709-4506-a974-646d78b519fb1505744965000",
"iat": 1505744965000,
"aud": "jincor.com",
"isTenant": true
}
}
+ Response 400 (application/json)
{
"error": "invalid token"
}
# Group User
## Create user [/user]
**Important note:**
"Scope" field is used to store user permissions.
It might be either just a string containing user role (e.g. "company-admin")
or an object describing what operations user can perform with resources (e.g. {
"company": [
"create",
"read",
"update",
"delete"
],
"employee": [
"read"
]
})
### Create new user [POST]
+ email `test@test.com` (string, required, email)
+ login `test@test.com` (string, required)
+ password `passwordA6` (string, required)
+ sub `Application specific subject, e.g. some ID in 3rd party service` (string, required)
+ scope `scope` (optional)
+ Request (application/json)
{
"login": "test_gmail.com",
"email": "test@gmail.com",
"password": "passw0Rd",
"sub": "test"
}
+ Response 200 (application/json)
{
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"login": "testuser",
"email": "test@test.com",
"tenant": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"scope": "user_scope",
"registrationDate": 1542384291572,
"lastActivity": 1542384471740
}
## List users [/user{?q}{?cursor}]
In case pagination requested the first value in response is always `cursor`. If you need to load the next page, provide cursor
in the next request parameter to load the next page. "0" is always for the first page if you see "0" in respone - there is no
next page. It doesnt apply if you search for users. Pagination for search requests is not supported
### List users for tenant [GET]
+ Parameters
+ q (string, optional)
query string to search users by login
+ cursor (string, optional)
cursor for pagination
+ Response 200 (application/json)
[
{
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"login": "testuser",
"email": "test@test.com",
"scope": "advisor",
"tenant": "c3a1e8d6-c361-4d55-8f26-e5134d804556",
"sub": "facebookId",
"registrationDate": 1542384291572,
"lastActivity": 1542384471740
},
{
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"login": "testuser",
"email": "test@test.com",
"scope": "advisor",
"tenant": "c3a1e8d6-c361-4d55-8f26-e5134d804556",
"sub": "facebookId",
"registrationDate": 1542384291572,
"lastActivity": 1542384471740
}
]
+ Response 200 (application/json)
[
"0",
{
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"login": "testuser",
"email": "test@test.com",
"tenant": "c3a1e8d6-c361-4d55-8f26-e5134d804556",
"scope": "advisor",
"sub": "facebookId",
"registrationDate": 1542384291572,
"lastActivity": 1542384471740
},
{
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"login": "testuser",
"email": "test@test.com",
"tenant": "c3a1e8d6-c361-4d55-8f26-e5134d804556",
"scope": "advisor",
"sub": "facebookId",
"registrationDate": 1542384291572,
"lastActivity": 1542384471740
}
]
## Delete user [/user/{login}]
### Delete a user [DELETE]
+ Response 200 (application/json)
{
"result": 1
}
+ Response 404 (application/json)
{
"error": "Specified login does not exist or was already deleted."
}
# Group Auth
## Login a user [/auth]
### Login [POST]
+ login `login` (string, required)
+ password `passwordA6` (string, required)
+ deviceId `someId` (string, required)
+ Request (application/json)
{
"login": "user_login",
"password": "password_hash",
"deviceId": "id"
}
+ Response 200 (application/json)
{
"accessToken": "jwt_token"
}
+ Response 403 (application/json)
{
"error": "Incorrect password",
"status": 403
}
+ Response 404 (application/json)
{
"error": "User does not exist",
"status": 404
}
+ Response 422 (application/json)
{
"error": {
"isJoi": true,
"name": "ValidationError",
"details": [
{
"message": "\"password\" length must be at least 6 characters long",
"path": "password",
"type": "string.min",
"context": {
"limit": 6,
"value": "test6",
"key": "password"
}
}
],
"_object": {
"email": "companies@jincor",
"password": "test6"
}
},
"value": {
"email": "companies@jincor",
"password": "test6"
}
}
## Verify token [/auth/verify]
### Verify [POST]
+ token `token` (string, required)
+ Request (application/json)
{
"token": "jwt_token"
}
+ Response 200 (application/json)
{
"decoded": {
"id": "0107bfcf-2f42-4e83-99e9-3ba44b737302",
"login": "tenant_id:test@test.com",
"scope": "user_scope",
"deviceId": "12345",
"jti": "0107bfcf-2f42-4e83-99e9-3ba44b737302123451498632187982",
"iat": 1498632187982,
"exp": 1498632792782
}
}
+ Response 400 (application/json)
{
"error": "invalid token"
}
## Logout [/auth/logout]
### Logout [POST]
+ token `token` (string, required)
+ Request (application/json)
{
"token": "jwt_token"
}
+ Response 200 (application/json)
{
"result": 1
}
+ Response 400 (application/json)
{
"error": "invalid token"
}