|
@ -66,14 +66,16 @@ let isPathExcluded = function (opts, path, method) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let authorizeToken = async function (ctx, token) { |
|
|
let authorizeToken = async function (ctx, token) { |
|
|
|
|
|
let startTime = moment() |
|
|
let rslt = null; |
|
|
let rslt = null; |
|
|
const tokenFormatRegexp = /^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$/g; |
|
|
const tokenFormatRegexp = /^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$/g; |
|
|
if (token && tokenFormatRegexp.test(token)) { |
|
|
if (token && tokenFormatRegexp.test(token)) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
console.log(`DurationCalc: auth 1 用时 ${moment().diff(startTime, 'milliseconds')}`); |
|
|
const authorizeRes = await ctx.app.fs.emisRequest.get('authorize', { |
|
|
const authorizeRes = await ctx.app.fs.emisRequest.get('authorize', { |
|
|
query: { token } |
|
|
query: { token } |
|
|
}) |
|
|
}) |
|
|
|
|
|
console.log(`DurationCalc: auth 2 用时 ${moment().diff(startTime, 'milliseconds')}`); |
|
|
const { userInfo, expired } = authorizeRes; |
|
|
const { userInfo, expired } = authorizeRes; |
|
|
if (expired && moment().valueOf() <= moment(expired).valueOf()) { |
|
|
if (expired && moment().valueOf() <= moment(expired).valueOf()) { |
|
|
const pomsUser = await ctx.app.fs.dc.models.User.findOne({ |
|
|
const pomsUser = await ctx.app.fs.dc.models.User.findOne({ |
|
@ -81,6 +83,7 @@ let authorizeToken = async function (ctx, token) { |
|
|
pepUserId: userInfo.id |
|
|
pepUserId: userInfo.id |
|
|
} |
|
|
} |
|
|
}) || {} |
|
|
}) || {} |
|
|
|
|
|
console.log(`DurationCalc: auth 3 用时 ${moment().diff(startTime, 'milliseconds')}`); |
|
|
rslt = { |
|
|
rslt = { |
|
|
'authorized': userInfo.authorized, |
|
|
'authorized': userInfo.authorized, |
|
|
'resources': (userInfo || {}).resources || [], |
|
|
'resources': (userInfo || {}).resources || [], |
|
@ -91,6 +94,7 @@ let authorizeToken = async function (ctx, token) { |
|
|
ctx.fs.api.pepUserInfo = userInfo; |
|
|
ctx.fs.api.pepUserInfo = userInfo; |
|
|
ctx.fs.api.token = token; |
|
|
ctx.fs.api.token = token; |
|
|
} |
|
|
} |
|
|
|
|
|
console.log(`DurationCalc: auth 4 用时 ${moment().diff(startTime, 'milliseconds')}`); |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
const { error } = err.response || {}; |
|
|
const { error } = err.response || {}; |
|
|
ctx.fs.logger.log('[anxinyun]', '[AUTH] failed', (error || {}).message || `cannot GET /users/${token}`); |
|
|
ctx.fs.logger.log('[anxinyun]', '[AUTH] failed', (error || {}).message || `cannot GET /users/${token}`); |
|
|