1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-31 01:47:11 +03:00

M #~: fix login in FireEdge (#2598)

(cherry picked from commit f3df091782692a63a7bcb58aa5c1196a801f3830)
This commit is contained in:
Jorge Miguel Lobo Escalona 2023-05-05 10:42:58 +02:00 committed by Tino Vázquez
parent b92e0f5837
commit ddecc5d8d9
3 changed files with 13 additions and 18 deletions

View File

@ -276,14 +276,14 @@ const validate2faAuthentication = (informationUser) => {
*/
const genJWT = (token, informationUser) => {
if (
token?.token &&
token?.time &&
token?.token &&
informationUser?.ID &&
informationUser?.NAME
) {
const { ID: id, TEMPLATE: userTemplate, NAME: username } = informationUser
const dataJWT = { id, user: username, token: token.token }
const jwt = createJWT(dataJWT)
const jwt = createJWT({ id, user: username, token: token.token })
if (jwt) {
const rtn = { token: jwt, id }
if (userTemplate?.SUNSTONE?.LANG) {
@ -302,7 +302,6 @@ const genJWT = (token, informationUser) => {
*/
const getCreatedTokenOpennebula = (username = '') => {
const { now, nowUnix, limitExpirationReuseToken } = setDates()
if (username && global?.users?.[username]?.tokens) {
let acc = { token: '', time: 0 }
global.users[username].tokens.forEach((curr = {}, index = 0) => {
@ -397,6 +396,7 @@ const createTokenServerAdmin = ({
return {
token: encrypt(`${serverAdmin}:${username}:${expire}`, key, iv),
time: expire,
}
}
}
@ -415,8 +415,7 @@ const wrapUserWithServerAdmin = (serverAdminData = {}, userData = {}) => {
if (
relativeTime &&
serverAdminData &&
serverAdminData.USER &&
serverAdminData?.USER &&
(serverAdminName = serverAdminData.USER.NAME) &&
(serverAdminPassword = serverAdminData.USER.PASSWORD) &&
userData &&

View File

@ -28,18 +28,14 @@ const { JWTError, MissingFireEdgeKeyError } = require('server/utils/errors')
* @param {string} jwtData.token - token opennebula
* @returns {string} JWT
*/
const createJWT = ({ id: iss, user: aud, token: jti }) => {
let rtn = null
if (iss && aud && jti) {
const payload = {
iss, // user ID
aud, // user name
jti, // token
}
rtn = jwtEncode(payload)
const createJWT = ({ id, user, token }) => {
if (id && user && token) {
return jwtEncode({
iss: id, // user ID
aud: user, // user name
jti: token, // token
})
}
return rtn
}
/**

View File

@ -535,7 +535,7 @@ const getSunstoneAuth = () => {
*/
const getDataZone = (zone = '0', configuredZones) => {
let rtn
const zones = (global && global.zones) || configuredZones
const zones = global?.zones || configuredZones
if (zones && Array.isArray(zones)) {
rtn = zones[0]
if (Number.isInteger(parseInt(zone, 10))) {