Skip to content

Commit ae6d30a

Browse files
committed
Added user service and authentication
1 parent 519fdb6 commit ae6d30a

File tree

66 files changed

+1747
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1747
-598
lines changed

config/default.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
{
2-
"auth": {
3-
"idField": "id",
4-
"local": {},
5-
"token": {
6-
"secret": "ThYncCxLbjhin7YZBtZgda7nm0KSeT4rM0UsvpCnJXPA6sTVq6NKvsDoHjzyjkMKnB4gKDqsUx8Gg7mYsRbV9Q=="
2+
"authentication": {
3+
"secret": "ThYncCxLbjhin7YZBtZgda7nm0KSeT4rM0UsvpCnJXPA6sTVq6NKvsDoHjzyjkMKnB4gKDqsUx8Gg7mYsRbV9Q==",
4+
"path": "/authentication",
5+
"service": "users",
6+
"jwt": {
7+
"header": {
8+
"type": "access"
9+
},
10+
"audience": "https://dendra.science",
11+
"issuer": "feathers",
12+
"algorithm": "HS256",
13+
"expiresIn": "1d"
14+
},
15+
"local": {
16+
"entity": "user",
17+
"service": "users",
18+
"usernameField": "email",
19+
"passwordField": "password"
720
}
821
},
922
"connections": {

config/production.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"apis": {
3-
"influxDB": {
4-
"url": "INFLUXDB_API_URL"
5-
}
2+
"authentication": {
3+
"secret": "WEB_API_SECRET"
64
},
75
"connections": {
86
"noaaGOES": {
@@ -30,5 +28,14 @@
3028
}
3129
}
3230
},
33-
"port": 8080
31+
"port": 8080,
32+
"services": {
33+
"influx_select": {
34+
"apis": {
35+
"default": {
36+
"url": "INFLUXDB_API_URL"
37+
}
38+
}
39+
}
40+
}
3441
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
'use strict';
22

3-
const authentication = require('feathers-authentication');
3+
const auth = require('feathers-authentication');
4+
const jwt = require('feathers-authentication-jwt');
5+
const local = require('feathers-authentication-local');
46

57
module.exports = function () {
68
return function () {
79
const app = this;
810

9-
let config = app.get('auth');
11+
app.configure(auth(app.get('authentication'))).configure(jwt()).configure(local());
1012

11-
app.configure(authentication(config));
13+
app.service('/authentication').hooks({
14+
before: {
15+
create: [auth.hooks.authenticate(['jwt', 'local'])],
16+
remove: [auth.hooks.authenticate('jwt')]
17+
}
18+
});
1219
};
1320
}();

dist/server/services/datapoint/hooks/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ var _math2 = _interopRequireDefault(_math);
77
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
88

99
const apiHooks = require('@dendra-science/api-hooks-common');
10-
// const globalHooks = require('../../../hooks')
11-
const hooks = require('feathers-hooks-common');
10+
const commonHooks = require('feathers-hooks-common');
1211
const { errors } = require('feathers-errors');
13-
const { getByDot } = require('feathers-hooks-common');
1412
const { treeMap } = require('@dendra-science/utils');
1513

1614
exports.before = {
@@ -123,19 +121,19 @@ exports.before = {
123121
}
124122
}],
125123

126-
get: hooks.disallow(),
127-
create: hooks.disallow(),
128-
update: hooks.disallow(),
129-
patch: hooks.disallow(),
130-
remove: hooks.disallow()
124+
get: commonHooks.disallow(),
125+
create: commonHooks.disallow(),
126+
update: commonHooks.disallow(),
127+
patch: commonHooks.disallow(),
128+
remove: commonHooks.disallow()
131129
};
132130

133131
exports.after = {
134132
// all: [],
135133

136134
find(hook) {
137-
const sourceUnitName = getByDot(hook, 'params.sourceUom.library_config.mathjs.unit_name');
138-
const targetUnitName = getByDot(hook, 'params.targetUom.library_config.mathjs.unit_name');
135+
const sourceUnitName = commonHooks.getByDot(hook, 'params.sourceUom.library_config.mathjs.unit_name');
136+
const targetUnitName = commonHooks.getByDot(hook, 'params.targetUom.library_config.mathjs.unit_name');
139137

140138
if (!sourceUnitName || !targetUnitName) return;
141139

dist/server/services/datapoint_lookup/hooks/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

3-
// const apiHooks = require('@dendra-science/api-hooks-common')
4-
// const globalHooks = require('../../../hooks')
5-
const hooks = require('feathers-hooks-common');
3+
const commonHooks = require('feathers-hooks-common');
64
const { errors } = require('feathers-errors');
75

86
// TODO: Allow POST request for longer query params?
@@ -24,11 +22,11 @@ exports.before = {
2422
if (!Array.isArray(datastreams)) throw new errors.BadRequest('Expected datastreams');
2523
}],
2624

27-
get: hooks.disallow(),
28-
create: hooks.disallow(),
29-
update: hooks.disallow(),
30-
patch: hooks.disallow(),
31-
remove: hooks.disallow()
25+
get: commonHooks.disallow(),
26+
create: commonHooks.disallow(),
27+
update: commonHooks.disallow(),
28+
patch: commonHooks.disallow(),
29+
remove: commonHooks.disallow()
3230
};
3331

3432
exports.after = {

dist/server/services/datastream/hooks/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

33
const apiHooks = require('@dendra-science/api-hooks-common');
4+
const auth = require('feathers-authentication');
5+
const authHooks = require('feathers-authentication-hooks');
6+
const commonHooks = require('feathers-hooks-common');
47
const globalHooks = require('../../../hooks');
5-
const hooks = require('feathers-hooks-common');
68
const { asyncHashDigest } = require('../../../lib/utils');
79
const { errors } = require('feathers-errors');
810

@@ -301,23 +303,29 @@ exports.computeHashes = computeHashes; // For testing
301303
exports.before = {
302304
// all: [],
303305

304-
find: apiHooks.coerceQuery(),
306+
find: [apiHooks.coerceQuery()],
305307

306308
// get: [],
307309

308-
create: [hooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes()],
310+
create: [auth.hooks.authenticate('jwt'), authHooks.restrictToRoles({
311+
roles: ['sys-admin']
312+
}), commonHooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes()],
309313

310-
update: [hooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes(), hook => {
314+
update: [auth.hooks.authenticate('jwt'), authHooks.restrictToRoles({
315+
roles: ['sys-admin']
316+
}), commonHooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes(), hook => {
311317
// TODO: Optimize with find/$select to return fewer fields?
312318
return hook.app.service('/datastreams').get(hook.id).then(doc => {
313319
hook.data.created_at = doc.created_at;
314320
return hook;
315321
});
316322
}],
317323

318-
patch: hooks.disallow('rest')
324+
patch: [commonHooks.disallow('rest')],
319325

320-
// remove: []
326+
remove: [auth.hooks.authenticate('jwt'), authHooks.restrictToRoles({
327+
roles: ['sys-admin']
328+
})]
321329
};
322330

323331
const uomSchema = {
@@ -350,7 +358,7 @@ const preferredUomsSchema = {
350358
};
351359

352360
exports.after = {
353-
all: [hooks.populate({ schema: uomSchema }), hooks.populate({ schema: convertibleToUomsSchema }), hooks.populate({ schema: preferredUomsSchema })]
361+
all: [commonHooks.populate({ schema: uomSchema }), commonHooks.populate({ schema: convertibleToUomsSchema }), commonHooks.populate({ schema: preferredUomsSchema })]
354362

355363
// find: [],
356364
// get: [],

dist/server/services/datastream_lookup/hooks/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22

33
const apiHooks = require('@dendra-science/api-hooks-common');
4-
// const globalHooks = require('../../../hooks')
5-
const hooks = require('feathers-hooks-common');
6-
// const {errors} = require('feathers-errors')
4+
const commonHooks = require('feathers-hooks-common');
75

86
// TODO: Allow POST request for longer query params?
97

@@ -12,11 +10,11 @@ exports.before = {
1210

1311
find: [apiHooks.splitList('params.query._id'), apiHooks.splitList('params.query.source'), apiHooks.splitList('params.query.station_id'), apiHooks.coerceQuery()],
1412

15-
get: hooks.disallow(),
16-
create: hooks.disallow(),
17-
update: hooks.disallow(),
18-
patch: hooks.disallow(),
19-
remove: hooks.disallow()
13+
get: commonHooks.disallow(),
14+
create: commonHooks.disallow(),
15+
update: commonHooks.disallow(),
16+
patch: commonHooks.disallow(),
17+
remove: commonHooks.disallow()
2018
};
2119

2220
exports.after = {

dist/server/services/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ const path = require('path');
55
module.exports = function () {
66
return function () {
77
const app = this;
8-
const serviceNames = [
9-
// 'authentication',
10-
'datapoint_lookup', // Route must precede datapoint
8+
const serviceNames = ['authentication', 'datapoint_lookup', // Route must precede datapoint
119
'datapoint', 'datastream_lookup', // Route must precede datastream
12-
'datastream', 'influx_select', 'legacy_datavalue', 'membership', 'organization', 'person', 'place', 'scheme', 'som', 'station', 'system_schema', 'system_time', 'thing', 'uom', 'vocabulary'];
10+
'datastream', 'influx_select', 'legacy_datavalue', 'membership', 'organization', 'person', 'place', 'scheme', 'som', 'station', 'system_schema', 'system_time', 'thing', 'uom', 'user', 'vocabulary'];
1311

1412
// Feathers configuration is synchronous, so use promises to wait for
1513
// async stuff like database connections, etc.

dist/server/services/influx_select/hooks/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22

33
const apiHooks = require('@dendra-science/api-hooks-common');
4-
// const globalHooks = require('../../../hooks')
5-
const hooks = require('feathers-hooks-common');
6-
// const {errors} = require('feathers-errors')
4+
const commonHooks = require('feathers-hooks-common');
75
const { treeMap } = require('@dendra-science/utils');
86

97
exports.before = {
@@ -50,13 +48,13 @@ exports.before = {
5048

5149
if (parts.length > 0) query.wc = parts.join(' AND ');
5250
}
53-
}, hooks.removeQuery('compact', 'time', 'time_adjust', 'utc_offset')],
51+
}, commonHooks.removeQuery('compact', 'time', 'time_adjust', 'utc_offset')],
5452

55-
get: hooks.disallow(),
56-
create: hooks.disallow(),
57-
update: hooks.disallow(),
58-
patch: hooks.disallow(),
59-
remove: hooks.disallow()
53+
get: commonHooks.disallow(),
54+
create: commonHooks.disallow(),
55+
update: commonHooks.disallow(),
56+
patch: commonHooks.disallow(),
57+
remove: commonHooks.disallow()
6058
};
6159

6260
exports.after = {

dist/server/services/legacy_datavalue/hooks/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22

33
const apiHooks = require('@dendra-science/api-hooks-common');
4-
// const globalHooks = require('../../../hooks')
5-
const hooks = require('feathers-hooks-common');
6-
// const {errors} = require('feathers-errors')
4+
const commonHooks = require('feathers-hooks-common');
75
const { treeMap } = require('@dendra-science/utils');
86

97
exports.before = {
@@ -34,13 +32,13 @@ exports.before = {
3432
if (typeof query.$sort === 'object' && typeof query.$sort.time !== 'undefined') {
3533
query.$sort = { local_date_time: query.$sort.time };
3634
}
37-
}, hooks.removeQuery('compact', 'time', 'time_adjust')],
35+
}, commonHooks.removeQuery('compact', 'time', 'time_adjust')],
3836

39-
get: hooks.disallow(),
40-
create: hooks.disallow(),
41-
update: hooks.disallow(),
42-
patch: hooks.disallow(),
43-
remove: hooks.disallow()
37+
get: commonHooks.disallow(),
38+
create: commonHooks.disallow(),
39+
update: commonHooks.disallow(),
40+
patch: commonHooks.disallow(),
41+
remove: commonHooks.disallow()
4442
};
4543

4644
exports.after = {

0 commit comments

Comments
 (0)