Browse Source

redis 鉴权数据查询

dev_trial
CODE 1 year ago
parent
commit
7ffc28208e
  1. 14
      code/VideoAccess-VCMP/api/app/lib/middlewares/authenticator.js

14
code/VideoAccess-VCMP/api/app/lib/middlewares/authenticator.js

@ -70,10 +70,16 @@ let authorizeToken = async function (ctx, token) {
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 {
const expired = await ctx.redis.hget(token, 'expired'); // const expired = await ctx.redis.hget(token, 'expired');
if (expired && moment().valueOf() <= moment(expired).valueOf()) { let userInfo = await ctx.redis.get(token);
const userInfo = JSON.parse(await ctx.redis.hget(token, 'userInfo')); if (
userInfo
// expired && moment().valueOf() <= moment(expired).valueOf()
) {
// const userInfo = JSON.parse(await ctx.redis.hget(token, 'userInfo'));
userInfo = JSON.parse(userInfo);
rslt = { rslt = {
'authorized': userInfo.authorized, 'authorized': userInfo.authorized,
'resources': (userInfo || {}).resources || [], 'resources': (userInfo || {}).resources || [],
@ -83,7 +89,7 @@ let authorizeToken = async function (ctx, token) {
ctx.fs.api.token = token; ctx.fs.api.token = token;
} }
} catch (err) { } catch (err) {
console.log(11111111111,err); console.error(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}`);
} }

Loading…
Cancel
Save