- 在调用API的时候,需要拼接签名字符串,现在鉴权方式是APP鉴权,需要用到AppKey、AppSecret进行签名计算。
- 将签名后的字符串X-Bce-Signature放入请求的header中,网关会通过对称计算签名来验证请求者的身份。
- 根据不同的鉴权方式,请求的Header中传入对应计算后的签名,将入参信息按照请求签名说明生成签名字符串,这样才能请求验证通过。
请求签名说明
1. 相关header
请求头 | 参数说明 |
---|---|
X-Bce-Signature | 签名字符串,具体参照签名校验文档 |
X-Bce-Stage | API发布环境,在当前环境发布了的API才能调用通过,目前取值为release,pre-online,test,不传默认release |
Host | default.gateway.com |
ContentType | application/json |
2. 签名校验
签名校验流程:
错误码列表:
编号 | 错误码 | 错误信息 | 描述 | HTTP状态码 |
---|---|---|---|---|
1 | EmptySignature | Signature is empty | 签名为空 | 400 |
2 | SignatureFormatInvalid | Signature is invalid: invalid signature format. | 签名格式错误 | 400 |
3 | SignatureAppInvalid | Signature is invalid: app key is invalid. | APP key不存在 | 400 |
4 | RequestTimeTooSkewed | The difference between the request time and the server's time is too large. | 客户端时间与服务器时间相差过多 | 403 |
5 | SignatureTimestampInvalid | Signature is invalid: timestamp is expired. | 签名过期 | 400 |
6 | SignatureTimestampExpired | Signature is invalid: signature is mismatched. | 签名值不匹配 | 400 |
7 | SignatureMismatch | Signature is invalid: timestamp is invalid. | 时间戳格式错误 | 400 |
APP签名请求示例
- 普通APP鉴权
POST /app/1 HTTP/1.1 X-Bce-Signature: bce-auth-v1/359117df989c4a3db52289bbb8d286fb/2018-12-06T03:05:00Z
/1800/content-type;host/4f2408c97f217f1a28b3771c816843656ede2e968ac1f912711560da7f31dafd Host: default1.gateway-mock.com Content-Type: application/json {}
- 云市场APP鉴权
POST /app/1 HTTP/1.1
X-Bce-Signature: AppCode/9ae2bf211459430e9cee594ff1d2a325
//后边是具体的appCode
Host: default1.gateway-mock.com
Content-Type: application/json
{}