1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

M #-: Remove "Token expired" in fireedge.log (#1192)

Signed-off-by: Jorge Lobo <jlobo@opennebula.io>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-05-07 10:31:04 +02:00 committed by Ruben S. Montero
parent a2f6375b44
commit 20ab78182a
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87

View File

@ -14,7 +14,6 @@
/* -------------------------------------------------------------------------- */
const jwt = require('jwt-simple')
const { DateTime } = require('luxon')
const { messageTerminal } = require('./general')
const createToken = (
@ -42,35 +41,38 @@ const validateAuth = req => {
const authorization = req.headers.authorization
const removeBearer = new RegExp('^Bearer ', 'i')
const token = authorization.replace(removeBearer, '')
try {
const payload = jwt.decode(token, global.FIREEDGE_KEY)
const now = DateTime.local()
if (
payload &&
'iss' in payload &&
'aud' in payload &&
'jti' in payload &&
'iat' in payload &&
'exp' in payload &&
payload.exp >= now.toSeconds()
) {
const { iss, aud, jti, iat, exp } = payload
rtn = {
iss,
aud,
jti,
iat,
exp
const fireedgeKey = global && global.FIREEDGE_KEY
if (token && fireedgeKey) {
try {
const payload = jwt.decode(token, fireedgeKey)
if (
payload &&
'iss' in payload &&
'aud' in payload &&
'jti' in payload &&
'iat' in payload &&
'exp' in payload
) {
const { iss, aud, jti, iat, exp } = payload
rtn = {
iss,
aud,
jti,
iat,
exp
}
}
} catch (error) {
}
} catch (error) {
const config = {
color: 'red',
type: 'ERROR',
error: (error && error.message) || '',
message: 'Error: %s'
} else {
const messageError = (!token && 'jwt') || (!fireedgeKey && 'fireedge_key')
if (messageError) {
messageTerminal({
color: 'red',
message: 'invalid: %s',
type: messageError
})
}
messageTerminal(config)
}
}
return rtn