diff --git a/src/fireedge/src/server/routes/api/auth/functions.js b/src/fireedge/src/server/routes/api/auth/functions.js index e27a5e393b..f70eabb7fa 100644 --- a/src/fireedge/src/server/routes/api/auth/functions.js +++ b/src/fireedge/src/server/routes/api/auth/functions.js @@ -161,15 +161,16 @@ const validate2faAuthentication = informationUser => { } const genJWT = (token, informationUser) => { - if (token && informationUser && informationUser.ID && informationUser.PASSWORD) { + if (token && token.token && informationUser && informationUser.ID && informationUser.PASSWORD) { const { ID: id, TEMPLATE: userTemplate } = informationUser - const dataJWT = { id, user, token } - const jwt = createToken(dataJWT, nowUnix, nowWithMinutes.toSeconds()) + const dataJWT = { id, user, token: token.token } + const addTime = token.expiration_time || nowWithMinutes.toSeconds() + const jwt = createToken(dataJWT, nowUnix, addTime) if (jwt) { if (!global.users) { global.users = {} } - global.users[user] = token + global.users[user] = token.token const rtn = { token: jwt, id } if (userTemplate && userTemplate.SUNSTONE && userTemplate.SUNSTONE.LANG) { rtn.language = userTemplate.SUNSTONE.LANG @@ -221,7 +222,7 @@ const setZones = () => { } } -const login = (userData) => { +const login = userData => { let rtn = true if (userData) { const findTextError = `[${namespace + defaultMethodUserInfo}]` @@ -272,7 +273,12 @@ const getValidOpennebulaToken = userDataTokens => { parseInt(token.EXPIRATION_TIME, 10) >= nowUnix + (parseInt(minimumExpirationTime, 10) * 60) ) }) - rtn = validToken && validToken.TOKEN + if (validToken && validToken.TOKEN && validToken.EXPIRATION_TIME) { + rtn = { + token: validToken.TOKEN, + expiration_time: validToken.EXPIRATION_TIME + } + } } return rtn } @@ -303,7 +309,7 @@ const authenticate = (token, userData) => { const findTextError = `[${namespace + defaultMethodLogin}]` if (token && userData) { if (token.indexOf(findTextError) < 0) { - genJWT(token, userData) + genJWT({ token }, userData) } } next() diff --git a/src/fireedge/src/server/routes/api/auth/index.js b/src/fireedge/src/server/routes/api/auth/index.js index 5dba33f8be..5f57ad3645 100644 --- a/src/fireedge/src/server/routes/api/auth/index.js +++ b/src/fireedge/src/server/routes/api/auth/index.js @@ -12,13 +12,13 @@ /* See the License for the specific language governing permissions and */ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -const { AUTH } = require('./string-routes'); -const { httpMethod } = require('server/utils/constants/defaults'); -const { auth } = require('./auth'); +const { AUTH } = require('./string-routes') +const { httpMethod } = require('server/utils/constants/defaults') +const { auth } = require('./auth') -const { POST } = httpMethod; +const { POST } = httpMethod -const privateRoutes = []; +const privateRoutes = [] const publicRoutes = [ { @@ -26,11 +26,11 @@ const publicRoutes = [ endpoint: AUTH, action: auth } -]; +] const functionRoutes = { private: privateRoutes, public: publicRoutes -}; +} -module.exports = functionRoutes; +module.exports = functionRoutes