巴林闲侠
2 years ago
6 changed files with 64 additions and 63 deletions
@ -0,0 +1,43 @@ |
|||
'use strict'; |
|||
const fs = require('fs'); |
|||
const moment = require('moment') |
|||
|
|||
module.exports = function (app, opts) { |
|||
|
|||
function judgeSuper (ctx) { |
|||
try { |
|||
const { userInfo = {} } = ctx.fs.api || {}; |
|||
const { role = [] } = userInfo |
|||
return role.includes('SuperAdmin') |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
} |
|||
} |
|||
|
|||
async function anxinStrucRange (ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { userInfo = {} } = ctx.fs.api || {}; |
|||
const { correlationProject = [] } = userInfo |
|||
|
|||
const bindRes = await models.ProjectCorrelation.findAll({ |
|||
where: { |
|||
pepProjectId: { $in: correlationProject } |
|||
} |
|||
}) |
|||
return bindRes.reduce((arr, b) => { |
|||
for (let sid of b.anxinProjectId) { |
|||
arr.add(sid); |
|||
} |
|||
return arr; |
|||
}, new Set()) |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
} |
|||
} |
|||
|
|||
return { |
|||
judgeSuper, |
|||
anxinStrucRange |
|||
} |
|||
} |
@ -1,54 +0,0 @@ |
|||
const fs = require('fs'); |
|||
|
|||
module.exports = function (app, opts) { |
|||
async function oauthParseAuthHeader (auth) { |
|||
if (!auth) { |
|||
throw new Error('参数无效: 未包含Authorization头'); |
|||
} |
|||
|
|||
const authSplit = auth.split('Basic'); |
|||
if (authSplit.length != 2) { |
|||
throw new Error('参数无效: Authorization头格式无效,请检查是否包含了"Basic "'); |
|||
} |
|||
|
|||
const authCode = authSplit[1]; |
|||
const apikey = Buffer.from(authCode, 'base64').toString(); |
|||
|
|||
const keySplit = apikey.split(':'); |
|||
if (keySplit.length != 2) { |
|||
throw new Error('参数无效:请检查Authorization头内容是否经过正确Base64编码'); |
|||
} |
|||
|
|||
return keySplit; |
|||
} |
|||
|
|||
async function oauthParseBody (body, type) { |
|||
let checked = true, token = ''; |
|||
if (type == 'apply' && body['grant_type'] != 'client_credentials') { |
|||
checked = false; |
|||
} else if (type == 'refresh') { |
|||
if (body['grant_type'] != 'refresh_token' || body['token'] == null) { |
|||
checked = false; |
|||
} else { |
|||
token = body['token']; |
|||
} |
|||
} else if (type == 'invalidate') { |
|||
if (body['token'] == null) { |
|||
checked = false; |
|||
} else { |
|||
token = body['token']; |
|||
} |
|||
} |
|||
|
|||
if (!checked) { |
|||
throw new Error('参数无效:请求正文中未包含正确的信息'); |
|||
} |
|||
|
|||
return token; |
|||
} |
|||
|
|||
return { |
|||
oauthParseAuthHeader, |
|||
oauthParseBody |
|||
} |
|||
} |
Loading…
Reference in new issue