提交 512c56ab 编写于 作者: d-u-a's avatar d-u-a

secret-net: 增加云端安全验证说明

上级 0097caeb
......@@ -90,7 +90,6 @@ uniCloud.callFunction({
})
```
- 云对象
客户端通过importObject调用云对象时,加入secret和secretMethods参数。
......@@ -102,6 +101,40 @@ uniCloud.importObject('object-name', {
})
```
## 服务器端
为了避免客户端伪造参数获取服务器敏感数据,应以服务器端为准,如果客户端携带的 `secretType` 不符合要求应拒绝响应数据
- callFunction
```js
exports.main = async (event, context) => {
const secretType = context.secretType
// secretType 是客户端调用 uniCloud.callFunction 传递的参数 secretType
if (secretType !== 'both' || secretType !== 'response') {
return null
}
}
```
- 云对象
```js
module.exports = {
async _before() {
const methodName = this.getMethodName()
const clientInfo = this.getClientInfo()
const secretType = clientInfo.secretType
// secretType 是客户端调用 uniCloud.importObject 传递的参数 secretMethods
if (methodName === 'login' && (secretType !== 'both' || secretType !== 'response')) {
throw new Error('secretType invalid')
}
}
}
```
**secretType 属性说明**@secretType
......@@ -117,6 +150,8 @@ uniCloud.importObject('object-name', {
`secretMethods` 是云对象中指定需要加密的方法名。可对每个方法配置,例如: `secretMethods: {'login':'both'}`,指定 `login` 方法的 `secretType` 为 both
## 小贴士
1. 安全是相对的,没有绝对的安全。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册