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

F #5380: reuse time of one token (#1196)

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-05-10 13:06:10 +02:00 committed by Ruben S. Montero
parent 2fb99391b3
commit 4d6cd4bc61
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
2 changed files with 21 additions and 15 deletions

View File

@ -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()

View File

@ -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