From 018987c8497a03365e07bd51bacca7003d575a43 Mon Sep 17 00:00:00 2001 From: chenruilong Date: Fri, 24 Mar 2023 17:39:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(uni-id-co):=20=E8=AF=B7=E6=B1=82=E9=89=B4?= =?UTF-8?q?=E6=9D=83=E6=94=AF=E6=8C=81=20uni-cloud-s2s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloudfunctions/uni-id-co/common/error.js | 2 +- .../middleware/verify-request-sign.js | 27 +++++++++++++++++++ .../cloudfunctions/uni-id-co/package.json | 7 ++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js index ef40377..1e33845 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js @@ -40,7 +40,7 @@ const ERROR = { UNSUPPORTED_REQUEST: 'uni-id-unsupported-request', ILLEGAL_REQUEST: 'uni-id-illegal-request', CONFIG_FIELD_REQUIRED: 'uni-id-config-field-required', - CONFIG_FIELD_INVALID: 'uni-frv-config-field-invalid', + CONFIG_FIELD_INVALID: 'uni-id-config-field-invalid', FRV_FAIL: 'uni-id-frv-fail', FRV_PROCESSING: 'uni-id-frv-processing', REAL_NAME_VERIFIED: 'uni-id-realname-verified', diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/middleware/verify-request-sign.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/middleware/verify-request-sign.js index 1565f22..1c12edc 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/middleware/verify-request-sign.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/middleware/verify-request-sign.js @@ -1,5 +1,11 @@ const crypto = require('crypto') +const createConfig = require('uni-config-center') +const { verifyHttpInfo } = require('uni-cloud-s2s') + const { ERROR } = require('../common/error') +const s2sConfig = createConfig({ + pluginId: 'uni-cloud-s2s' +}) const needSignFunctions = new Set([ 'externalRegister', 'externalLogin', @@ -20,6 +26,27 @@ module.exports = function () { } } + // 支持 uni-cloud-s2s 验证请求 + if (s2sConfig.hasFile('config.json')) { + try { + if (!verifyHttpInfo(this.getHttpInfo())) { + throw { + errCode: ERROR.ILLEGAL_REQUEST + } + } + } catch (e) { + if (e.errSubject === 'uni-cloud-s2s') { + throw { + errCode: ERROR.ILLEGAL_REQUEST, + errMsg: e.errMsg + } + } + throw e + } + + return + } + if (!this.config.requestAuthSecret || typeof this.config.requestAuthSecret !== 'string') { throw { errCode: ERROR.CONFIG_FIELD_REQUIRED, diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json index 1bbfed9..278aacd 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json @@ -1,6 +1,6 @@ { "name": "uni-id-co", - "version": "1.1.8", + "version": "1.1.9", "description": "", "main": "index.js", "keywords": [], @@ -11,11 +11,12 @@ "uni-captcha": "file:../../../../uni-captcha/uniCloud/cloudfunctions/common/uni-captcha", "uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center", "uni-id-common": "file:../../../../uni-id-common/uniCloud/cloudfunctions/common/uni-id-common", - "uni-open-bridge-common": "file:../../../../uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common" + "uni-open-bridge-common": "file:../../../../uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common", + "uni-cloud-s2s": "file:../../../../uni-cloud-s2s/uniCloud/cloudfunctions/common/uni-cloud-s2s" }, "extensions": { - "uni-cloud-sms": {}, "uni-cloud-redis": {}, + "uni-cloud-sms": {}, "uni-cloud-verify": {} }, "cloudfunction-config": { -- GitLab