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

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

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

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

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

Loading…
Cancel
Save