acebase-server 1.7.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acebase-server",
3
- "version": "1.7.0",
3
+ "version": "1.9.1",
4
4
  "description": "AceBase realtime database server (webserver endpoint to allow remote connections)",
5
5
  "main": "./src/index.js",
6
6
  "private": false,
@@ -44,13 +44,15 @@
44
44
  "author": "Ewout Stortenbeker <me@appy.one> (http://appy.one)",
45
45
  "license": "MIT",
46
46
  "dependencies": {
47
- "acebase": "^1.12.2",
48
- "acebase-core": "^1.10.1",
47
+ "acebase": "^1.15.3",
48
+ "acebase-core": "^1.13.1",
49
49
  "express": "^4.17.1",
50
50
  "socket.io": "^2.4.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/express": "^4.17.13",
54
- "@types/node": "^14.0.14"
54
+ "@types/node": "^14.0.14",
55
+ "swagger-jsdoc": "^6.1.0",
56
+ "swagger-ui-express": "^4.3.0"
55
57
  }
56
58
  }
@@ -1015,6 +1015,7 @@ class AceBaseServer extends EventEmitter {
1015
1015
  catch(err) {
1016
1016
  this.debug.error(`Failed to parse AceBase-Context header: "${context}" in request at ${req.url} from client ${req.ip}`);
1017
1017
  }
1018
+ // console.log(`Received request on path ` + req.path);
1018
1019
  next();
1019
1020
  });
1020
1021
 
@@ -1253,11 +1254,11 @@ class AceBaseServer extends EventEmitter {
1253
1254
  if (typeof details !== 'object' || typeof details.uid !== 'string' || typeof details.password !== 'string' || typeof details.new_password !== 'string') {
1254
1255
  logRef.push({ action: 'change_password', success: false, code: 'invalid_details', ip: req.ip, date: new Date() });
1255
1256
  res.status(400).send('Bad Request'); // Bad Request
1256
- return;
1257
+ return;
1257
1258
  }
1258
- if (details.new_password.length < 8 || ~details.new_password.indexOf(' ') || !/[0-9]/.test(details.new_password) || !/[a-z]/.test(details.new_password) || !/[A-Z]/.test(details.new_password)) {
1259
+ if (details.new_password.length < 8 || details.new_password.includes(' ') || !/[0-9]/.test(details.new_password) || !/[a-z]/.test(details.new_password) || !/[A-Z]/.test(details.new_password)) {
1259
1260
  logRef.push({ action: 'change_password', success: false, code: 'new_password_denied', ip: req.ip, date: new Date(), uid: details.uid });
1260
- err = 'Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)';
1261
+ const err = 'Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)';
1261
1262
  res.status(422).send(err);// Unprocessable Entity
1262
1263
  return;
1263
1264
  }
@@ -1368,6 +1369,11 @@ class AceBaseServer extends EventEmitter {
1368
1369
 
1369
1370
  const details = req.body;
1370
1371
 
1372
+ if (typeof details.displayName === 'undefined' && typeof details.display_name === 'string') {
1373
+ // Allow display_name to be sent also (which is used in update endpoint)
1374
+ details.displayName = details.display_name;
1375
+ }
1376
+
1371
1377
  // Check if sent details are ok
1372
1378
  let err;
1373
1379
  if (!details.username && !details.email) {
@@ -1485,6 +1491,11 @@ class AceBaseServer extends EventEmitter {
1485
1491
  return sendUnauthorizedError(res, 'unauthorized_update', 'You are not authorized to perform this update. This attempt has been logged.');
1486
1492
  }
1487
1493
 
1494
+ if (typeof details.display_name === 'undefined' && typeof details.displayName === 'string') {
1495
+ // Allow displayName to be sent also (which is used in signup endpoint)
1496
+ details.display_name = details.displayName;
1497
+ }
1498
+
1488
1499
  // Check if sent details are ok
1489
1500
  let err;
1490
1501
  if (details.email && !isValid.email(details.email)) {
@@ -1579,13 +1590,13 @@ class AceBaseServer extends EventEmitter {
1579
1590
 
1580
1591
  if (req.user.uid !== 'admin' && (details.uid !== req.user.uid || typeof details.is_disabled === 'boolean')) {
1581
1592
  logRef.push({ action: 'delete', success: false, code: 'unauthorized_delete', auth_uid: req.user.uid, delete_uid: details.uid, ip: req.ip, date: new Date() });
1582
- return sendUnauthorizedError(res, 'unauthorized_update', 'You are not authorized to perform this operation, your attempt has been logged');
1593
+ return sendUnauthorizedError(res, 'unauthorized_delete', 'You are not authorized to perform this operation, your attempt has been logged');
1583
1594
  }
1584
1595
 
1585
1596
  const uid = details.uid || req.user.uid;
1586
1597
  if (uid === 'admin') {
1587
1598
  logRef.push({ action: 'delete', success: false, code: 'unauthorized_delete', auth_uid: req.user.uid, delete_uid: details.uid, ip: req.ip, date: new Date() });
1588
- return sendUnauthorizedError(res, 'unauthorized_update', 'The admin account cannot be deleted, your attempt has been logged');
1599
+ return sendUnauthorizedError(res, 'unauthorized_delete', 'The admin account cannot be deleted, your attempt has been logged');
1589
1600
  }
1590
1601
  return authRef.child(uid)
1591
1602
  .remove()
@@ -1606,12 +1617,16 @@ class AceBaseServer extends EventEmitter {
1606
1617
  const callbackUrl = req.query.callbackUrl;
1607
1618
  const options = Object.keys(req.query).filter(key => key.startsWith('option_')).reduce((options, key) => {
1608
1619
  const name = key.slice(7);
1609
- options[name] = req.query[key];
1620
+ let value = req.query[key];
1621
+ if (['true','false'].includes(value)) { value = value === 'true'; }
1622
+ else if (/^\-?[0-9]+$/.test(value)) { value = parseInt(value); }
1623
+ options[name] = value;
1624
+ return options;
1610
1625
  }, {});
1611
1626
  const signedInUid = req.user && req.user.uid;
1612
1627
  const provider = this.authProviders[providerName];
1613
1628
  if (!provider) {
1614
- throw new Error(`Provider ${provider} is not available, or not properly configured by the db admin`);
1629
+ throw new Error(`Provider ${providerName} is not available, or not properly configured by the db admin`);
1615
1630
  }
1616
1631
  // Create secure state so it cannot be tampered with. hash it with a server-only known salt: the generated admin password salt
1617
1632
  await this.ready();
@@ -1862,7 +1877,11 @@ class AceBaseServer extends EventEmitter {
1862
1877
  expires_in: tokens.expires_in
1863
1878
  },
1864
1879
  access_token: createPublicAccessToken(user.uid, req.ip, user.access_token, _secureObjectsSalt),
1865
- user: getPublicAccountDetails(user)
1880
+
1881
+ // Disabled sending user details because:
1882
+ // 1) they might be too big to send as redirect header,
1883
+ // 2) client should verify the sent access token and get user details from the server
1884
+ // user: getPublicAccountDetails(user)
1866
1885
  };
1867
1886
 
1868
1887
  if (state.flow === 'socket') {
@@ -1909,6 +1928,13 @@ class AceBaseServer extends EventEmitter {
1909
1928
  });
1910
1929
  }
1911
1930
 
1931
+ // If environment is development, add API docs
1932
+ if (process.env.NODE_ENV === 'development') {
1933
+ this.debug.warn('DEVELOPMENT MODE: adding API docs endpoint at /docs');
1934
+ const addAPIDocsRoute = require('./routes/docs').default;
1935
+ addAPIDocsRoute(app);
1936
+ }
1937
+
1912
1938
  const webManagerDir = `/webmanager/`;
1913
1939
  app.get('/', (req, res) => {
1914
1940
  res.redirect(webManagerDir);
@@ -1920,24 +1946,6 @@ class AceBaseServer extends EventEmitter {
1920
1946
  // Send default file
1921
1947
  res.sendFile(__dirname + '/webmanager/index.html');
1922
1948
  }
1923
- // else if (filePath === 'TEST') {
1924
- // // apply test
1925
- // let test;
1926
- // if (req.query.type === 'update') {
1927
- // let val = req.query.val;
1928
- // if (val[0] === '{') { val = JSON.parse(val); }
1929
- // test = db.ref(req.query.path || '').update(val);
1930
- // }
1931
- // else {
1932
- // res.send('');
1933
- // }
1934
- // return test && test.then(() => {
1935
- // res.send('ok');
1936
- // })
1937
- // .catch(err => {
1938
- // res.send('fail: ' + err.message);
1939
- // });
1940
- // }
1941
1949
  else {
1942
1950
  res.sendFile(__dirname + '/webmanager/' + filePath);
1943
1951
  }
@@ -1950,7 +1958,7 @@ class AceBaseServer extends EventEmitter {
1950
1958
 
1951
1959
  app.get(`/info/${dbname}`, (req, res) => {
1952
1960
  const info = {
1953
- version: '1.7.0', // TODO: Load from package.json
1961
+ version: '1.9.1', // TODO: Load from package.json
1954
1962
  time: Date.now(),
1955
1963
  process: process.pid
1956
1964
  };
@@ -2121,43 +2129,77 @@ class AceBaseServer extends EventEmitter {
2121
2129
  });
2122
2130
  });
2123
2131
 
2124
- app.get(`/export/${dbname}/*`, (req, res) => {
2132
+ app.get(`/export/${dbname}/*`, async (req, res) => {
2125
2133
  // Export API
2126
- const path = req.path.substr(dbname.length + 9);
2134
+ const path = req.path.slice(dbname.length + 9);
2127
2135
  if (!userHasAccess(req.user, path, false, denyDetails => sendUnauthorizedError(res, denyDetails.code, denyDetails.message))) {
2128
2136
  return;
2129
2137
  }
2130
2138
  const format = req.query.format || 'json';
2139
+ const type_safe = req.query.type_safe !== '0';
2131
2140
 
2132
- const stream = {
2133
- write(chunk) {
2134
- res.write(chunk);
2135
-
2136
- // OLD: causes streaming issues
2137
- // return new Promise((resolve, reject) => {
2138
- // res.write(chunk, err => {
2139
- // if (err) { reject(err); }
2140
- // else { resolve(); }
2141
- // });
2142
- // });
2141
+ const write = async (chunk) => {
2142
+ let ok = res.write(chunk);
2143
+ if (!ok) {
2144
+ await new Promise(resolve => res.once('drain', resolve));
2143
2145
  }
2144
2146
  };
2145
2147
 
2146
2148
  const ref = db.ref(path);
2147
2149
  res.setHeader('Content-Disposition', `attachment; filename=${ref.key || 'export'}.json`); // Will be treated as a download in browser
2148
2150
 
2149
- ref.export(stream, { format })
2150
- .then(() => {
2151
+ try {
2152
+ await ref.export(write, { format, type_safe });
2153
+ }
2154
+ catch (err) {
2155
+ this.debug.error(`Error exporting data for path "/${path}": `, err);
2156
+ if (!res.headersSent) {
2157
+ res.statusCode = 500;
2158
+ res.send(err);
2159
+ }
2160
+ }
2161
+ finally {
2151
2162
  res.end();
2152
- })
2153
- .catch(err => {
2154
- res.statusCode = 500;
2155
- res.send(err);
2156
- })
2157
- .catch(err => {
2158
- // Previous catch raised another exception. Happens when streaming already started: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
2163
+ }
2164
+ });
2165
+
2166
+ app.post(`/import/${dbname}/*`, async (req, res) => {
2167
+ // Import API
2168
+ const path = req.path.slice(dbname.length + 9);
2169
+ if (!userHasAccess(req.user, path, false, denyDetails => sendUnauthorizedError(res, denyDetails.code, denyDetails.message))) {
2170
+ return;
2171
+ }
2172
+ const format = req.query.format || 'json';
2173
+ const suppress_events = req.query.suppress_events === '1';
2174
+
2175
+ req.pause(); // Switch to non-flowing mode so we can use .read() upon request
2176
+ let eof = false;
2177
+ req.once('end', () => { eof = true; });
2178
+ const read = async (length) => {
2179
+ let chunk = req.read();
2180
+ if (chunk === null && !eof) {
2181
+ await new Promise(resolve => req.once('readable', resolve));
2182
+ chunk = req.read();
2183
+ }
2184
+ console.log(`Received chunk: `, chunk);
2185
+ return chunk;
2186
+ };
2187
+
2188
+ const ref = db.ref(path);
2189
+ try {
2190
+ await ref.import(read, { format, suppress_events });
2191
+ res.send({ success: true });
2192
+ }
2193
+ catch (err) {
2194
+ this.debug.error(`Error importing data for path "/${path}": `, err);
2195
+ if (!res.headersSent) {
2196
+ res.statusCode = 500;
2197
+ res.send({ success: false, reason: err.message });
2198
+ }
2199
+ }
2200
+ finally {
2159
2201
  res.end();
2160
- });
2202
+ }
2161
2203
  });
2162
2204
 
2163
2205
  app.get(`/exists/${dbname}/*`, (req, res) => {
@@ -2215,12 +2257,12 @@ class AceBaseServer extends EventEmitter {
2215
2257
  }
2216
2258
  catch(err) {
2217
2259
  if (err instanceof SchemaValidationError) {
2218
- logRef.push({ action: 'update_data', success: false, code: 'schema_validation_failed', path, error: err.reason });
2260
+ logRef && logRef.push({ action: 'update_data', success: false, code: 'schema_validation_failed', path, error: err.reason });
2219
2261
  res.status(422).send({ code: 'schema_validation_failed', message: err.message });
2220
2262
  }
2221
2263
  else {
2222
2264
  this.debug.error(`failed to update "${path}":`, err);
2223
- logRef.push({ action: 'update_data', success: false, code: `unknown_error`, path, error: err.message });
2265
+ logRef && logRef.push({ action: 'update_data', success: false, code: `unknown_error`, path, error: err.message });
2224
2266
  sendError(res, err);
2225
2267
  }
2226
2268
  }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("path");
4
+ const swaggerJsdoc = require("swagger-jsdoc");
5
+ const swaggerUi = require("swagger-ui-express");
6
+ // import config from '../config';
7
+ const addRoute = (app) => {
8
+ // Generate docs from all yaml files
9
+ const options = {
10
+ definition: {
11
+ openapi: '3.0.0',
12
+ info: {
13
+ title: 'AceBase Server API',
14
+ description: 'AceBase Server API',
15
+ version: '1.0.0',
16
+ contact: {
17
+ name: 'Ewout Stortenbeker',
18
+ email: 'me@appy.one'
19
+ },
20
+ },
21
+ tags: [{
22
+ name: 'auth',
23
+ description: 'User authentication endpoints'
24
+ }, {
25
+ name: 'oauth2',
26
+ description: 'User authentication using 3rd party OAuth2 providers'
27
+ }],
28
+ components: {
29
+ securitySchemes: {
30
+ bearerAuth: {
31
+ type: 'http',
32
+ scheme: 'bearer',
33
+ bearerFormat: 'token' // switch to JWT in the future?
34
+ }
35
+ },
36
+ schemas: {
37
+ User: {
38
+ type: 'object',
39
+ properties: {
40
+ uid: { type: 'string', example: 'jpx0k53u0002ecr7s354c51l' },
41
+ username: { type: 'string', example: 'someuser' },
42
+ email: { type: 'string', example: 'email@domain.com' },
43
+ displayName: { type: 'string', example: 'Some User' },
44
+ picture: {
45
+ type: 'object',
46
+ properties: {
47
+ width: { type: 'number', example: 500 },
48
+ height: { type: 'number', example: 500 },
49
+ url: { type: 'string', example: 'https://profile.pic/user.jpg' }
50
+ }
51
+ },
52
+ emailVerified: { type: 'boolean', example: true },
53
+ created: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
54
+ prevSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
55
+ prevSigninIp: { type: 'string', example: '127.0.0.1' },
56
+ lastSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
57
+ lastSigninIp: { type: 'string', example: '127.0.0.1' },
58
+ changePassword: { type: 'boolean', example: false },
59
+ changePasswordRequested: { type: 'boolean', example: false },
60
+ changePasswordBefore: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
61
+ settings: { type: 'object' }
62
+ }
63
+ },
64
+ Error: {
65
+ type: 'object',
66
+ properties: {
67
+ code: { type: 'string', description: 'error code', example: 'invalid_request' },
68
+ message: { type: 'string', description: 'The error message', example: 'Invalid request for this endpoint' }
69
+ }
70
+ },
71
+ UnexpectedError: {
72
+ type: 'object',
73
+ properties: {
74
+ code: { type: 'string', value: 'unexpected', description: 'The string `"unexpected"`' },
75
+ message: { type: 'string', description: 'The server error message' }
76
+ }
77
+ },
78
+ UnknownError: {
79
+ type: 'object',
80
+ properties: {
81
+ code: { type: 'string', value: 'unknown', description: 'The string `"unknown"`' },
82
+ message: { type: 'string', description: 'The server error message' }
83
+ }
84
+ }
85
+ }
86
+ },
87
+ security: [
88
+ // Enable bearer auth globally
89
+ { bearerAuth: [] }
90
+ ],
91
+ },
92
+ apis: [path.resolve(__dirname, '../ts/routes/*.yaml')]
93
+ };
94
+ const swaggerDocs = swaggerJsdoc(options);
95
+ app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
96
+ };
97
+ exports.default = addRoute;
@@ -0,0 +1,76 @@
1
+ /auth/{dbname}/change_password:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Change a user's password
6
+ description: Changes a user account's password by providing the current and new passwords
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: request object
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ uid:
23
+ type: string
24
+ description: Account's uid
25
+ password:
26
+ type: string
27
+ description: Current password set on the account
28
+ new_password:
29
+ type: string
30
+ description: New password to set on the account
31
+ required:
32
+ - uid
33
+ - password
34
+ - new_password
35
+ responses:
36
+ 200:
37
+ description: If the password change is successful, returns an object with a new access token
38
+ content:
39
+ 'application/json':
40
+ schema:
41
+ type: object
42
+ properties:
43
+ access_token:
44
+ description: New access token that provides access to API calls that require authentication.
45
+ type: string
46
+ example: ewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
47
+ user:
48
+ $ref: '#/components/schemas/User'
49
+ 400:
50
+ description: Returns a `"400 Bad Request"` if the sent request is invalid. If the request is missing details, response is the string `"Bad Request"`. Otherwise, it's an object with `code` and `message` properties. Possible codes are `"unknown_uid"`, `"wrong_password"`, `"wrong_access_token"` (if not signed in as the user the password change was requested for)
51
+ content:
52
+ 'text/plain':
53
+ schema:
54
+ type: string
55
+ value: Bad Request
56
+ example: Bad Request
57
+ 'application/json':
58
+ schema:
59
+ $ref: '#/components/schemas/Error'
60
+ example:
61
+ code: wrong_access_token
62
+ message: "Cannot change password while signed in as other user, or with an old token"
63
+ 422:
64
+ description: New password does not meet the criteria
65
+ content:
66
+ 'text/plain':
67
+ schema:
68
+ type: string
69
+ value: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
70
+ example: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
71
+ 500:
72
+ description: An unexpected error occurred
73
+ content:
74
+ 'application/json':
75
+ schema:
76
+ $ref: '#/components/schemas/UnexpectedError'
@@ -0,0 +1,78 @@
1
+ /auth/{dbname}/delete:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Delete a user account
6
+ description: Deletes an existing user account
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: Account to delete
17
+ content:
18
+ 'text/plain':
19
+ schema:
20
+ type: string
21
+ value: ''
22
+ example: ''
23
+ description: Empty content to delete signed in user account
24
+ 'application/json':
25
+ schema:
26
+ type: object
27
+ properties:
28
+ uid:
29
+ type: string
30
+ description: (admin user only) to delete a specific user account, the target account `uid` must be passed with the request
31
+ example: jpx0k53u0002ecr7s354c51l
32
+ responses:
33
+ 200:
34
+ description: When delete succeeds, it returns the string `"Farewell"`
35
+ content:
36
+ 'text/plain':
37
+ schema:
38
+ type: text
39
+ value: Farewell
40
+ example: Farewell
41
+ 401:
42
+ description: If this is an unauthenticated request (not signed in), `"401 Unauthorized"` is returned
43
+ content:
44
+ 'application/json':
45
+ schema:
46
+ type: object
47
+ properties:
48
+ code:
49
+ type: string
50
+ value: unauthenticated_delete
51
+ message:
52
+ type: string
53
+ value: You are not authorized to perform this operation, your attempt has been logged
54
+ example:
55
+ code: unauthenticated_delete
56
+ message: You are not authorized to perform this operation, your attempt has been logged
57
+ 403:
58
+ description: If a non-admin user tries to update a user's account details, `"403 Forbidden"` is returned
59
+ content:
60
+ 'application/json':
61
+ schema:
62
+ type: object
63
+ properties:
64
+ code:
65
+ type: string
66
+ value: unauthorized_delete
67
+ message:
68
+ type: string
69
+ value: You are not authorized to perform this operation. This attempt has been logged.
70
+ example:
71
+ code: unauthorized_delete
72
+ message: You are not authorized to perform this operation. This attempt has been logged.
73
+ 500:
74
+ description: An unenexpected error occurred on the server
75
+ content:
76
+ 'application/json':
77
+ schema:
78
+ $ref: '#/components/schemas/UnexpectedError'
@@ -0,0 +1,50 @@
1
+ /auth/{dbname}/forgot_password:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Issue a password reset
6
+ description: Issues a password reset for a user that forgot their password. User must have an email address in the database.
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: user details
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ email:
23
+ type: string
24
+ description: User's email address. A password reset email will be sent to this address
25
+ required:
26
+ - email
27
+ responses:
28
+ 200:
29
+ description: If a password reset email has been successfully sent, returns the string `"OK"`
30
+ content:
31
+ 'text/plain':
32
+ schema:
33
+ type: 'string'
34
+ value: OK
35
+ description: The string `"OK"`
36
+ 400:
37
+ description: Returns a `"400 Bad Request"` if the server has not been configured properly, or if no or invalid email address was sent with the request
38
+ content:
39
+ 'application/json':
40
+ schema:
41
+ $ref: '#/components/schemas/Error'
42
+ example:
43
+ code: invalid_email
44
+ message: Email address not found, or duplicate entries found
45
+ 500:
46
+ description: An unexpected error occurred
47
+ content:
48
+ 'application/json':
49
+ schema:
50
+ $ref: '#/components/schemas/UnexpectedError'
@@ -0,0 +1,54 @@
1
+ /auth/{dbname}/reset_password:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Completes a password reset
6
+ description: Completes a password reset request for a user account with a code sent to the email address by the `forgot_password` endpoint
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: verification object
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ code:
23
+ type: string
24
+ description: Password reset code that was sent to the user's email address
25
+ password:
26
+ type: string
27
+ description: New password to set on the account
28
+ required:
29
+ - code
30
+ - password
31
+ responses:
32
+ 200:
33
+ description: If the password reset is successful, returns the string `"OK"`
34
+ content:
35
+ 'text/plain':
36
+ schema:
37
+ type: 'string'
38
+ value: OK
39
+ description: The string `"OK"`
40
+ 400:
41
+ description: Returns a `"401 Bad Request"` if the code sent with the request is invalid, or the new password doesn't meet the requirements
42
+ content:
43
+ 'application/json':
44
+ schema:
45
+ $ref: '#/components/schemas/Error'
46
+ example:
47
+ code: invalid_code
48
+ message: Invalid token
49
+ 500:
50
+ description: An unexpected error occurred
51
+ content:
52
+ 'application/json':
53
+ schema:
54
+ $ref: '#/components/schemas/UnexpectedError'