Skip to content

Commit 63d3278

Browse files
authored
Merge pull request #102 from coder-mind-project/develop
Version 1.1.4 released!
2 parents be1fca4 + 37ad836 commit 63d3278

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Owner: Coder Mind
1010

1111
E-mail (Project owner): allan@codermind.com.br
1212

13-
Stable release: http://master.codermind.com.br
13+
Stable release: https://master.codermind.com.br
1414

15-
Latest release: http://master-homolog.codermind.com.br
15+
Latest release: https://master-homolog.codermind.com.br
1616
___
1717

1818
## Docs:

api/auth/auth.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const jwt = require('jwt-simple')
22
const { SECRET_AUTH_PACKAGE, issuer } = require('../../config/environment')
33
const captcha = require('../../config/recaptcha/captcha.js')
4+
const { tokenDuration, tokenEmission, nowInSecs } = require('../../config/authentication/tokenrules')
45

56
/**
67
* @function
@@ -82,12 +83,11 @@ module.exports = app => {
8283
user.password = null
8384

8485
const now = Math.floor(Date.now() / 1000)
85-
const tenDaysLater = 60 * 60 * 24 * 10
8686

8787
const payload = {
8888
iss: issuer,
89-
iat: now,
90-
exp: now + tenDaysLater,
89+
iat: tokenEmission,
90+
exp: tokenDuration,
9191
user: {
9292
_id: user._id || user.id,
9393
name: user.name,
@@ -128,7 +128,7 @@ module.exports = app => {
128128
let token = { ...req.body }.token
129129
const { secret } = SECRET_AUTH_PACKAGE
130130

131-
const payload = token ? await jwt.decode(token, secret) : {}
131+
const payload = token ? await jwt.decode(token, secret, true) : {}
132132

133133
if (payload.iss !== issuer) {
134134
throw {
@@ -144,6 +144,13 @@ module.exports = app => {
144144
}
145145
}
146146

147+
if (!payload.exp || !payload.iat || nowInSecs() > payload.exp) {
148+
throw {
149+
name: 'expired',
150+
description: 'Acesso não autorizado'
151+
}
152+
}
153+
147154
let user = await User.findOne({ _id: payload.user._id, deletedAt: null })
148155

149156
if (user && user._id) {

api/responses.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module.exports = app => {
180180
msg: 'Ocorreu um erro desconhecido, se persistir reporte'
181181
}
182182

183-
const { name, description } = { ...stack }
183+
const { name, description } = stack
184184

185185
switch (description) {
186186
case 'Captcha inválido':
@@ -201,7 +201,8 @@ module.exports = app => {
201201
pending = name
202202
reformulatedError.msg = description
203203

204-
reformulatedError[pending] = 'pending'
204+
reformulatedError[pending || 'InternalError'] = 'pending'
205+
205206
return reformulatedError
206207
}
207208

config/authentication/tokenrules.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const nowInSecs = () => Math.floor(Date.now() / 1000)
2+
3+
module.exports = {
4+
tokenEmission: nowInSecs(),
5+
tokenDuration: nowInSecs() + 60 * 60 * 24 * 10, // 10 days
6+
nowInSecs
7+
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "master-api",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Master api for Coder Mind platform",
55
"main": "index.js",
66
"scripts": {
@@ -28,16 +28,16 @@
2828
"dotenv": "^8.2.0",
2929
"express": "^4.17.1",
3030
"jwt-simple": "^0.5.6",
31-
"mongoose": "^5.7.5",
3231
"knex": "^0.19.5",
32+
"mongoose": "^5.7.5",
3333
"mongoose-seed": "^0.6.0",
3434
"mongoose-unique-validator": "^2.0.3",
3535
"multer": "^1.4.2",
3636
"multer-s3": "^2.9.0",
3737
"mysql": "^2.17.1",
3838
"node-schedule": "^1.3.2",
3939
"nodemailer": "^6.3.0",
40-
"passport": "^0.4.0",
40+
"passport": "^0.4.1",
4141
"passport-jwt": "^4.0.0",
4242
"pm2": "^4.4.0"
4343
},

0 commit comments

Comments
 (0)