Kaynağa Gözat

:recycle: lock-down every route

jwt
j 3 yıl önce
ebeveyn
işleme
a5ed5322fd

+ 1
- 0
backend/lib/auth/strategies/jwt.js Dosyayı Görüntüle

10
             aud: 'urn:audience:test',
10
             aud: 'urn:audience:test',
11
             iss: 'urn:issuer:test',
11
             iss: 'urn:issuer:test',
12
             sub: false,
12
             sub: false,
13
+            maxAgeSec: 14400, // 4 hours
13
         },
14
         },
14
         validate: (artifacts, request, h) => {
15
         validate: (artifacts, request, h) => {
15
             try {
16
             try {

+ 20
- 15
backend/lib/routes/health/get.js Dosyayı Görüntüle

8
     handlerType: 'health',
8
     handlerType: 'health',
9
     docs: {
9
     docs: {
10
         description: 'Get server stats',
10
         description: 'Get server stats',
11
-        notes: 'Returns stats on server status'
12
-    }
11
+        notes: 'Returns stats on server status',
12
+    },
13
+    opts: {
14
+        tags: ['api'],
15
+        auth: { strategy: 'default_jwt' },
16
+        cors: true,
17
+    },
13
 }
18
 }
14
 
19
 
15
 const validators = {}
20
 const validators = {}
16
 
21
 
17
 const responseSchemas = {
22
 const responseSchemas = {
18
     health: healthSchema.stats,
23
     health: healthSchema.stats,
19
-    error: errorSchema.single
24
+    error: errorSchema.single,
20
 }
25
 }
21
 
26
 
22
 module.exports = {
27
 module.exports = {
23
     method: 'GET',
28
     method: 'GET',
24
     path: '/',
29
     path: '/',
25
-    options:{
30
+    options: {
26
         ...pluginConfig.docs,
31
         ...pluginConfig.docs,
27
-        tags: ['api'],
28
-        auth: false,
29
-        cors: true,
32
+        ...pluginConfig.opts,
30
         handler: async function (request, h) {
33
         handler: async function (request, h) {
31
             const { healthService } = request.server.services()
34
             const { healthService } = request.server.services()
32
             const stats = await healthService.getStats()
35
             const stats = await healthService.getStats()
33
             try {
36
             try {
34
-                return h.response(({
35
-                    ok:true,
36
-                    handler: pluginConfig.handlerType,
37
-                    data: stats
38
-                })).code(200)
37
+                return h
38
+                    .response({
39
+                        ok: true,
40
+                        handler: pluginConfig.handlerType,
41
+                        data: stats,
42
+                    })
43
+                    .code(200)
39
             } catch (err) {
44
             } catch (err) {
40
                 return h
45
                 return h
41
                     .response({
46
                     .response({
42
                         ok: false,
47
                         ok: false,
43
                         handler: pluginConfig.handlerType,
48
                         handler: pluginConfig.handlerType,
44
-                        data: {error: `${err}`}
49
+                        data: { error: `${err}` },
45
                     })
50
                     })
46
                     .code(409)
51
                     .code(409)
47
             }
52
             }
48
         },
53
         },
49
         validate: {
54
         validate: {
50
             ...validators,
55
             ...validators,
51
-            failAction: 'log'
56
+            failAction: 'log',
52
         },
57
         },
53
 
58
 
54
         response: {
59
         response: {
66
             },
71
             },
67
         },
72
         },
68
     },
73
     },
69
-}
74
+}

+ 6
- 4
backend/lib/routes/membership/active.js Dosyayı Görüntüle

12
         description: 'active memberships',
12
         description: 'active memberships',
13
         notes: 'A list of groupings with active membership',
13
         notes: 'A list of groupings with active membership',
14
     },
14
     },
15
+    opts: {
16
+        tags: ['api'],
17
+        auth: { strategy: 'default_jwt' },
18
+        cors: true,
19
+    },
15
 }
20
 }
16
 
21
 
17
 const validators = {
22
 const validators = {
57
     path: '/{profile_id}',
62
     path: '/{profile_id}',
58
     options: {
63
     options: {
59
         ...pluginConfig.docs,
64
         ...pluginConfig.docs,
60
-        tags: ['api'],
61
-        /** Protect this route with authentication? */
62
-        auth: false,
63
-        cors: true,
65
+        ...pluginConfig.opts,
64
         handler: async function (request, h) {
66
         handler: async function (request, h) {
65
             const { membershipService, profileService } =
67
             const { membershipService, profileService } =
66
                 request.server.services()
68
                 request.server.services()

+ 6
- 3
backend/lib/routes/membership/join.js Dosyayı Görüntüle

11
         description: 'join',
11
         description: 'join',
12
         notes: 'Join a grouping by creating a membership record',
12
         notes: 'Join a grouping by creating a membership record',
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 const validators = {
21
 const validators = {
37
     path: '/{profile_id}/join',
42
     path: '/{profile_id}/join',
38
     options: {
43
     options: {
39
         ...pluginConfig.docs,
44
         ...pluginConfig.docs,
40
-        tags: ['api'],
41
-        auth: false,
42
-        cors: true,
45
+        ...pluginConfig.opts,
43
 
46
 
44
         /**
47
         /**
45
          * Join a grouping by creating a membership record
48
          * Join a grouping by creating a membership record

+ 6
- 2
backend/lib/routes/membership/leave.js Dosyayı Görüntüle

8
         description: 'leave',
8
         description: 'leave',
9
         notes: 'Leave a grouping by editing a membership record',
9
         notes: 'Leave a grouping by editing a membership record',
10
     },
10
     },
11
+    opts: {
12
+        tags: ['api'],
13
+        auth: { strategy: 'default_jwt' },
14
+        cors: true,
15
+    },
11
 }
16
 }
12
 
17
 
13
 const validators = {
18
 const validators = {
21
     path: '/leave',
26
     path: '/leave',
22
     options: {
27
     options: {
23
         ...pluginConfig.docs,
28
         ...pluginConfig.docs,
24
-        tags: ['api'],
25
-        auth: false,
29
+        ...pluginConfig.opts,
26
         handler: async function (request, h) {
30
         handler: async function (request, h) {
27
             try {
31
             try {
28
                 return {
32
                 return {

+ 7
- 3
backend/lib/routes/membership/reveal.js Dosyayı Görüntüle

9
         description: 'reveal',
9
         description: 'reveal',
10
         notes: 'Reveal profile information to a grouping by membership',
10
         notes: 'Reveal profile information to a grouping by membership',
11
     },
11
     },
12
+    opts: {
13
+        tags: ['api'],
14
+        auth: { strategy: 'default_jwt' },
15
+        cors: true,
16
+    },
12
 }
17
 }
13
 
18
 
14
 const validators = {
19
 const validators = {
22
     }),
27
     }),
23
     error: errorSchema.single,
28
     error: errorSchema.single,
24
 }
29
 }
30
+
25
 module.exports = {
31
 module.exports = {
26
     method: 'POST',
32
     method: 'POST',
27
     path: '/{grouping_id}/reveal',
33
     path: '/{grouping_id}/reveal',
28
     options: {
34
     options: {
29
         ...pluginConfig.docs,
35
         ...pluginConfig.docs,
30
-        tags: ['api'],
31
-        auth: false,
32
-        cors: true,
36
+        ...pluginConfig.opts,
33
         handler: async function (request, h) {
37
         handler: async function (request, h) {
34
             const { membershipService, profileService } =
38
             const { membershipService, profileService } =
35
                 request.server.services()
39
                 request.server.services()

+ 6
- 6
backend/lib/routes/notification/index.js Dosyayı Görüntüle

1
-const Joi = require('joi')
2
-const apiSchema = require('../../schemas/api')
3
-const errorSchema = require('../../schemas/errors')
4
 const params = require('../../schemas/params')
1
 const params = require('../../schemas/params')
5
 
2
 
6
 const pluginConfig = {
3
 const pluginConfig = {
9
         description: 'subscribe',
6
         description: 'subscribe',
10
         notes: 'Subscribe to notifications based on profile_id',
7
         notes: 'Subscribe to notifications based on profile_id',
11
     },
8
     },
9
+    opts: {
10
+        tags: ['api'],
11
+        auth: { strategy: 'default_jwt' },
12
+        cors: true,
13
+    },
12
 }
14
 }
13
 
15
 
14
 const validators = {
16
 const validators = {
20
     path: '/{profile_id}/subscribe',
22
     path: '/{profile_id}/subscribe',
21
     options: {
23
     options: {
22
         ...pluginConfig.docs,
24
         ...pluginConfig.docs,
23
-        tags: ['api'],
24
-        auth: false,
25
-        cors: true,
25
+        ...pluginConfig.opts,
26
         handler: async (request, h) => {
26
         handler: async (request, h) => {
27
             const { profile_id } = request.params
27
             const { profile_id } = request.params
28
 
28
 

+ 6
- 4
backend/lib/routes/profile/get.js Dosyayı Görüntüle

11
         description: 'Returns a single profile with tags',
11
         description: 'Returns a single profile with tags',
12
         notes: 'returns from the Profiles Table',
12
         notes: 'returns from the Profiles Table',
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 const responseSchemas = {
21
 const responseSchemas = {
27
     path: '/{profile_id}',
32
     path: '/{profile_id}',
28
     options: {
33
     options: {
29
         ...pluginConfig.docs,
34
         ...pluginConfig.docs,
30
-        tags: ['api'],
31
-        /** Protect this route with authentication? */
32
-        auth: false,
33
-        cors: true,
35
+        ...pluginConfig.opts,
34
         handler: async function (request, h) {
36
         handler: async function (request, h) {
35
             const { profile_id } = request.params
37
             const { profile_id } = request.params
36
             const { profileService } = request.server.services()
38
             const { profileService } = request.server.services()

+ 6
- 3
backend/lib/routes/profile/match.js Dosyayı Görüntüle

10
         description: 'matches',
10
         description: 'matches',
11
         notes: 'Match everyone',
11
         notes: 'Match everyone',
12
     },
12
     },
13
+    opts: {
14
+        tags: ['api'],
15
+        auth: { strategy: 'default_jwt' },
16
+        cors: true,
17
+    },
13
 }
18
 }
14
 
19
 
15
 const validators = {}
20
 const validators = {}
24
     path: '/match',
29
     path: '/match',
25
     options: {
30
     options: {
26
         ...pluginConfig.docs,
31
         ...pluginConfig.docs,
27
-        tags: ['api'],
28
-        /** Protect this route with authentication? */
29
-        auth: false,
32
+        ...pluginConfig.opts,
30
 
33
 
31
         handler: async function (request, h) {
34
         handler: async function (request, h) {
32
             const { matchService, matchQueueService } =
35
             const { matchService, matchQueueService } =

+ 6
- 4
backend/lib/routes/profile/patch-queue.js Dosyayı Görüntüle

12
         description: 'Updates match queue in place',
12
         description: 'Updates match queue in place',
13
         notes: 'Updates in place and does not delete from table',
13
         notes: 'Updates in place and does not delete from table',
14
     },
14
     },
15
+    opts: {
16
+        tags: ['api'],
17
+        auth: { strategy: 'default_jwt' },
18
+        cors: true,
19
+    },
15
 }
20
 }
16
 
21
 
17
 const responseSchemas = {
22
 const responseSchemas = {
34
     path: '/{profile_id}/queue/{target_id}/delete',
39
     path: '/{profile_id}/queue/{target_id}/delete',
35
     options: {
40
     options: {
36
         ...pluginConfig.docs,
41
         ...pluginConfig.docs,
37
-        tags: ['api'],
38
-        /** Protect this route with authentication? */
39
-        auth: false,
40
-        cors: true,
42
+        ...pluginConfig.opts,
41
         handler: async function (request, h) {
43
         handler: async function (request, h) {
42
             const { profile_id, target_id } = request.params
44
             const { profile_id, target_id } = request.params
43
             const { include_profile, reinsert } = request.query
45
             const { include_profile, reinsert } = request.query

+ 6
- 4
backend/lib/routes/profile/queue.js Dosyayı Görüntüle

12
         description: 'Returns previously scored profiles',
12
         description: 'Returns previously scored profiles',
13
         notes: 'returns from the MatchQueue Table',
13
         notes: 'returns from the MatchQueue Table',
14
     },
14
     },
15
+    opts: {
16
+        tags: ['api'],
17
+        auth: { strategy: 'default_jwt' },
18
+        cors: true,
19
+    },
15
 }
20
 }
16
 
21
 
17
 const responseSchemas = {
22
 const responseSchemas = {
31
     path: '/{profile_id}/queue',
36
     path: '/{profile_id}/queue',
32
     options: {
37
     options: {
33
         ...pluginConfig.docs,
38
         ...pluginConfig.docs,
34
-        tags: ['api'],
35
-        /** Protect this route with authentication? */
36
-        auth: false,
37
-        cors: true,
39
+        ...pluginConfig.opts,
38
         handler: async function (request, h) {
40
         handler: async function (request, h) {
39
             const { profile_id } = request.params
41
             const { profile_id } = request.params
40
             const { include_profile } = request.query
42
             const { include_profile } = request.query

+ 6
- 4
backend/lib/routes/profile/respond.js Dosyayı Görüntüle

12
         description: 'Update profile',
12
         description: 'Update profile',
13
         notes: 'Update profile responses',
13
         notes: 'Update profile responses',
14
     },
14
     },
15
+    opts: {
16
+        tags: ['api'],
17
+        auth: { strategy: 'default_jwt' },
18
+        cors: true,
19
+    },
15
 }
20
 }
16
 
21
 
17
 const responseSchemas = {
22
 const responseSchemas = {
40
     path: '/{profile_id}/respond',
45
     path: '/{profile_id}/respond',
41
     options: {
46
     options: {
42
         ...pluginConfig.docs,
47
         ...pluginConfig.docs,
43
-        tags: ['api'],
44
-        /** Protect this route with authentication? */
45
-        auth: false,
46
-        cors: true,
48
+        ...pluginConfig.opts,
47
         handler: async function (request, h) {
49
         handler: async function (request, h) {
48
             const { profileService } = request.services()
50
             const { profileService } = request.services()
49
 
51
 

+ 6
- 4
backend/lib/routes/profile/score.js Dosyayı Görüntüle

12
         description: 'scores',
12
         description: 'scores',
13
         notes: 'A list of profile scores',
13
         notes: 'A list of profile scores',
14
     },
14
     },
15
+    opts: {
16
+        tags: ['api'],
17
+        auth: { strategy: 'default_jwt' },
18
+        cors: true,
19
+    },
15
 }
20
 }
16
 
21
 
17
 const validators = {
22
 const validators = {
40
     path: '/{profile_id}/score',
45
     path: '/{profile_id}/score',
41
     options: {
46
     options: {
42
         ...pluginConfig.docs,
47
         ...pluginConfig.docs,
43
-        tags: ['api'],
44
-        /** Protect this route with authentication? */
45
-        auth: false,
46
-        cors: true,
48
+        ...pluginConfig.opts,
47
         handler: async function (request, h) {
49
         handler: async function (request, h) {
48
             const { profileService, matchQueueService } =
50
             const { profileService, matchQueueService } =
49
                 request.server.services()
51
                 request.server.services()

+ 6
- 4
backend/lib/routes/profile/update.js Dosyayı Görüntüle

12
         description: 'Update profile',
12
         description: 'Update profile',
13
         notes: 'Update profile responses',
13
         notes: 'Update profile responses',
14
     },
14
     },
15
+    opts: {
16
+        tags: ['api'],
17
+        auth: { strategy: 'default_jwt' },
18
+        cors: true,
19
+    },
15
 }
20
 }
16
 
21
 
17
 const responseSchemas = {
22
 const responseSchemas = {
37
     path: '/{profile_id}/update/{response_id?}',
42
     path: '/{profile_id}/update/{response_id?}',
38
     options: {
43
     options: {
39
         ...pluginConfig.docs,
44
         ...pluginConfig.docs,
40
-        tags: ['api'],
41
-        /** Protect this route with authentication? */
42
-        auth: false,
43
-
45
+        ...pluginConfig.opts,
44
         handler: async function (request, h) {
46
         handler: async function (request, h) {
45
             const { profileService } = request.services()
47
             const { profileService } = request.services()
46
             const profileId = request.params.profile_id
48
             const profileId = request.params.profile_id

+ 6
- 4
backend/lib/routes/survey/questions.js Dosyayı Görüntüle

10
         description: 'Get survey questions',
10
         description: 'Get survey questions',
11
         notes: 'Returns a list of all possible survey questions in the form of response_keys',
11
         notes: 'Returns a list of all possible survey questions in the form of response_keys',
12
     },
12
     },
13
+    opts: {
14
+        tags: ['api'],
15
+        auth: false,
16
+        cors: true,
17
+    },
13
 }
18
 }
14
 
19
 
15
 /** Validator functions by request method */
20
 /** Validator functions by request method */
32
     path: '/questions',
37
     path: '/questions',
33
     options: {
38
     options: {
34
         ...pluginConfig.docs,
39
         ...pluginConfig.docs,
35
-        tags: ['api'],
36
-        /** Protect this route with authentication? */
37
-        auth: false,
38
-        cors: true,
40
+        ...pluginConfig.opts,
39
         handler: async function (request, h) {
41
         handler: async function (request, h) {
40
             const { responseService } = request.services()
42
             const { responseService } = request.services()
41
             const responseKeys = await responseService.getResponseKeys()
43
             const responseKeys = await responseService.getResponseKeys()

+ 6
- 3
backend/lib/routes/survey/responses.js Dosyayı Görüntüle

11
         description: 'Get responses to questions',
11
         description: 'Get responses to questions',
12
         notes: 'Returns a list of all survey responses for a user',
12
         notes: 'Returns a list of all survey responses for a user',
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 /** Validator functions by request method */
21
 /** Validator functions by request method */
33
     path: '/questions',
38
     path: '/questions',
34
     options: {
39
     options: {
35
         ...pluginConfig.docs,
40
         ...pluginConfig.docs,
36
-        tags: ['api'],
37
-        /** Protect this route with authentication? */
38
-        auth: false,
41
+        ...pluginConfig.opts,
39
 
42
 
40
         handler: async function (request, h) {
43
         handler: async function (request, h) {
41
             const { responseService } = request.services()
44
             const { responseService } = request.services()

+ 6
- 4
backend/lib/routes/tag/get.js Dosyayı Görüntüle

11
         description: 'Get tags based on membership id',
11
         description: 'Get tags based on membership id',
12
         notes: 'returns from the Tag Associations Table',
12
         notes: 'returns from the Tag Associations Table',
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 const responseSchemas = {
21
 const responseSchemas = {
31
     path: '/{profile_id}/tags/{grouping_id}',
36
     path: '/{profile_id}/tags/{grouping_id}',
32
     options: {
37
     options: {
33
         ...pluginConfig.docs,
38
         ...pluginConfig.docs,
34
-        tags: ['api'],
35
-        /** Protect this route with authentication? */
36
-        auth: false,
37
-        cors: true,
39
+        ...pluginConfig.opts,
38
         handler: async function (request, h) {
40
         handler: async function (request, h) {
39
             const { grouping_id, profile_id } = request.params
41
             const { grouping_id, profile_id } = request.params
40
             const { profileService } = request.server.services()
42
             const { profileService } = request.server.services()

+ 7
- 4
backend/lib/routes/tag/reveal.js Dosyayı Görüntüle

11
         description: 'Reveals part of a profile based on tag',
11
         description: 'Reveals part of a profile based on tag',
12
         notes: 'returns from the Tag Associations Table',
12
         notes: 'returns from the Tag Associations Table',
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 const responseSchemas = {
21
 const responseSchemas = {
31
     path: '/{profile_id}/reveal/{tag_id}',
36
     path: '/{profile_id}/reveal/{tag_id}',
32
     options: {
37
     options: {
33
         ...pluginConfig.docs,
38
         ...pluginConfig.docs,
34
-        tags: ['api'],
35
-        /** Protect this route with authentication? */
36
-        auth: false,
37
-        cors: true,
39
+        ...pluginConfig.opts,
40
+
38
         handler: async function (request, h) {
41
         handler: async function (request, h) {
39
             const { profile_id, tag_id } = request.params
42
             const { profile_id, tag_id } = request.params
40
             const { profileService } = request.server.services()
43
             const { profileService } = request.server.services()

+ 7
- 5
backend/lib/routes/user/authentication.js Dosyayı Görüntüle

11
             notes: 'Returns a password by the user email passed in the path',
11
             notes: 'Returns a password by the user email passed in the path',
12
         },
12
         },
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 /** Validator functions by request method */
21
 /** Validator functions by request method */
17
 const validators = {
22
 const validators = {
18
     /** Validate the route params (/active/{thing}) */
23
     /** Validate the route params (/active/{thing}) */
19
-    params: params.userEmail
24
+    params: params.userEmail,
20
 }
25
 }
21
 
26
 
22
 module.exports = {
27
 module.exports = {
24
     path: '/{user_email}/password',
29
     path: '/{user_email}/password',
25
     options: {
30
     options: {
26
         ...pluginConfig.docs.get,
31
         ...pluginConfig.docs.get,
27
-        tags: ['api'],
28
-        // auth: 'default_jwt',
29
-        auth: false,
30
-        cors: true,
32
+        ...pluginConfig.opts,
31
         handler: async function (request, h) {
33
         handler: async function (request, h) {
32
             try {
34
             try {
33
                 const { userService } = request.services()
35
                 const { userService } = request.services()

+ 6
- 4
backend/lib/routes/user/create-profile.js Dosyayı Görüntüle

10
         description: 'Create profile for user',
10
         description: 'Create profile for user',
11
         notes: 'Create a profile associated with this user',
11
         notes: 'Create a profile associated with this user',
12
     },
12
     },
13
+    opts: {
14
+        tags: ['api'],
15
+        auth: { strategy: 'default_jwt' },
16
+        cors: true,
17
+    },
13
 }
18
 }
14
 
19
 
15
 const validators = {
20
 const validators = {
44
     path: '/{user_id}/profile',
49
     path: '/{user_id}/profile',
45
     options: {
50
     options: {
46
         ...pluginConfig.docs,
51
         ...pluginConfig.docs,
47
-        tags: ['api'],
48
-        /** Protect this route with authentication? */
49
-        auth: false,
50
-        cors: true,
52
+        ...pluginConfig.opts,
51
         handler: async function (request, h) {
53
         handler: async function (request, h) {
52
             const { userService, profileService } = request.server.services()
54
             const { userService, profileService } = request.server.services()
53
             const userId = request.params.user_id
55
             const userId = request.params.user_id

+ 6
- 2
backend/lib/routes/user/current.js Dosyayı Görüntüle

11
             notes: 'Returns a user item by the id passed in the path',
11
             notes: 'Returns a user item by the id passed in the path',
12
         },
12
         },
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 /** Validator functions by request method */
21
 /** Validator functions by request method */
25
     path: '/{name}',
30
     path: '/{name}',
26
     options: {
31
     options: {
27
         ...pluginConfig.docs.get,
32
         ...pluginConfig.docs.get,
28
-        tags: ['api'],
29
-        auth: 'default_jwt',
33
+        ...pluginConfig.opts,
30
         handler: async function (request, h) {
34
         handler: async function (request, h) {
31
             try {
35
             try {
32
                 const auth = {
36
                 const auth = {

+ 6
- 4
backend/lib/routes/user/list-profiles.js Dosyayı Görüntüle

11
         description: 'profiles',
11
         description: 'profiles',
12
         notes: 'A list of profiles associated with this user',
12
         notes: 'A list of profiles associated with this user',
13
     },
13
     },
14
+    opts: {
15
+        tags: ['api'],
16
+        auth: { strategy: 'default_jwt' },
17
+        cors: true,
18
+    },
14
 }
19
 }
15
 
20
 
16
 const validators = {
21
 const validators = {
36
     path: '/{user_id}/profiles',
41
     path: '/{user_id}/profiles',
37
     options: {
42
     options: {
38
         ...pluginConfig.docs,
43
         ...pluginConfig.docs,
39
-        tags: ['api'],
40
-        /** Protect this route with authentication? */
41
-        auth: false,
42
-        cors: true,
44
+        ...pluginConfig.opts,
43
         handler: async function (request, h) {
45
         handler: async function (request, h) {
44
             const { userService, profileService } = request.server.services()
46
             const { userService, profileService } = request.server.services()
45
             const userId = request.params.user_id
47
             const userId = request.params.user_id

+ 6
- 3
backend/lib/routes/user/login.js Dosyayı Görüntüle

10
         description: 'login',
10
         description: 'login',
11
         notes: 'Attempt login',
11
         notes: 'Attempt login',
12
     },
12
     },
13
+    opts: {
14
+        tags: ['api'],
15
+        auth: false,
16
+        cors: true,
17
+    },
13
 }
18
 }
14
 
19
 
15
 /** Validator functions by request method */
20
 /** Validator functions by request method */
19
             user_email: Joi.string(),
24
             user_email: Joi.string(),
20
             password: Joi.string(),
25
             password: Joi.string(),
21
         }),
26
         }),
22
-        
23
     },
27
     },
24
     user: userSchema.single,
28
     user: userSchema.single,
25
     error: errorSchema.single,
29
     error: errorSchema.single,
30
     path: '/login',
34
     path: '/login',
31
     options: {
35
     options: {
32
         ...pluginConfig.docs,
36
         ...pluginConfig.docs,
33
-        tags: ['api'],
34
-        auth: false,
37
+        ...pluginConfig.opts,
35
         handler: async function (request, h) {
38
         handler: async function (request, h) {
36
             try {
39
             try {
37
                 const { userService } = request.services()
40
                 const { userService } = request.services()

+ 8
- 5
backend/lib/routes/user/signup.js Dosyayı Görüntüle

10
         description: 'Create a user',
10
         description: 'Create a user',
11
         notes: 'Create a user and other things',
11
         notes: 'Create a user and other things',
12
     },
12
     },
13
+    opts: {
14
+        tags: ['api'],
15
+        auth: false,
16
+        cors: true,
17
+    },
13
 }
18
 }
14
 
19
 
15
 const validators = {
20
 const validators = {
35
     path: '/signup',
40
     path: '/signup',
36
     options: {
41
     options: {
37
         ...pluginConfig.docs,
42
         ...pluginConfig.docs,
38
-        tags: ['api'],
39
-        /** Protect this route with authentication? */
40
-        auth: false,
41
-        cors: true,
43
+        ...pluginConfig.opts,
44
+
42
         handler: async function (request, h) {
45
         handler: async function (request, h) {
43
             const { userService } = request.server.services()
46
             const { userService } = request.server.services()
44
             const res = request.payload
47
             const res = request.payload
56
                         is_admin: 0,
59
                         is_admin: 0,
57
                         is_verified: 0,
60
                         is_verified: 0,
58
                     },
61
                     },
59
-                    created_at: Date.now()
62
+                    created_at: Date.now(),
60
                 })
63
                 })
61
                 return h
64
                 return h
62
                     .response({
65
                     .response({

+ 1
- 31
backend/lib/services/user.js Dosyayı Görüntüle

5
 const Schmervice = require('@hapipal/schmervice')
5
 const Schmervice = require('@hapipal/schmervice')
6
 const SecurePassword = require('secure-password')
6
 const SecurePassword = require('secure-password')
7
 
7
 
8
-const hasher = async (pwd, steak) => {
9
-    const hash = await pwd.hash(steak)
10
-    const result = await pwd.verify(steak, hash)
11
-    let squirtle = null
12
-
13
-    switch (result) {
14
-        case SecurePassword.INVALID_UNRECOGNIZED_HASH:
15
-            return console.error(
16
-                'This hash was not made with secure-password. Attempt legacy algorithm',
17
-            )
18
-        case SecurePassword.INVALID:
19
-            return console.log('Invalid password')
20
-        case SecurePassword.VALID:
21
-            return result
22
-        case SecurePassword.VALID_NEEDS_REHASH:
23
-            console.log('Yay you made it, wait for us to improve your safety')
24
-            try {
25
-                squirtle = await pwd.hash(steak)
26
-                // console.log('improvedHash', squirtle)
27
-                // const saveHash = Auth.insert({user_email: matchingEmails}, ).into('token')
28
-                return squirtle
29
-            } catch (err) {
30
-                console.error(
31
-                    'You are authenticated, but we could not improve your safety this time around',
32
-                )
33
-            }
34
-            break
35
-    }
36
-}
37
-
38
 /** Class for methods used in the User plugin */
8
 /** Class for methods used in the User plugin */
39
 module.exports = class UserService extends Schmervice.Service {
9
 module.exports = class UserService extends Schmervice.Service {
40
     /**
10
     /**
185
                 algorithm: 'HS256',
155
                 algorithm: 'HS256',
186
             },
156
             },
187
             {
157
             {
188
-                ttlSec: 4 * 60 * 60, // 7 days
158
+                ttlSec: 14400, // 4 hours
189
             },
159
             },
190
         )
160
         )
191
     }
161
     }

Loading…
İptal
Kaydet