Browse Source

OAuth2

release_1.3.0
巴林闲侠 3 years ago
parent
commit
3b4e90c91c
  1. 15
      code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js
  2. 2
      code/VideoAccess-VCMP/api/app/lib/utils/oauth2.js
  3. 1
      code/VideoAccess-VCMP/api/config.js

15
code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js

@ -5,10 +5,10 @@ const uuid = require('uuid');
async function check (ctx) {
try {
const { models } = this.fs.dc;
const { Authorization } = ctx.headers;
const { models } = ctx.fs.dc;
const { authorization } = ctx.headers;
const { utils: { oauthParseAuthHeader, oauthParseBody } } = ctx.app.fs
const keySplit = await oauthParseAuthHeader(Authorization);
const keySplit = await oauthParseAuthHeader(authorization);
const existRes = await models.Application.findOne({
where: {
appKey: keySplit[0],
@ -16,18 +16,15 @@ async function check (ctx) {
}
})
if (!existRes) {
throw '应用不存在'
throw new Error('应用不存在');
} else if (existRes.forbidden) {
throw '应用已被禁用'
throw new Error('应用已被禁用');
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body =
typeof error == 'string' ? {
message: error
} : error
ctx.body = error
}
}

2
code/VideoAccess-VCMP/api/app/lib/utils/oauth2.js

@ -1,3 +1,5 @@
const fs = require('fs');
module.exports = function (app, opts) {
async function oauthParseAuthHeader (auth) {
if (!auth) {

1
code/VideoAccess-VCMP/api/config.js

@ -93,6 +93,7 @@ const product = {
dev,
exclude: [
{ p: '/camera', o: 'GET' }, // 暂时滴
{ p: '/application/check', o: 'GET' }, // 暂时滴
], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由
redis: {
host: IOTA_REDIS_SERVER_HOST,

Loading…
Cancel
Save