创建消费者凭证
更新时间:2026-11-30
该接口用于为指定消费者创建认证凭证,支持 API Key、AK/SK 和 JWT 三种类型。创建成功后会刷新相关实例的鉴权配置。
注意事项:
apiKeyConfig仅 API_KEY 类型可传,jwtConfig仅 JWT 类型可传;传入与类型不匹配的配置会报参数错误。- API Key 支持系统生成和自定义(8~12 位),自定义值在当前账号内必须唯一;AK/SK 由系统生成;每个消费者最多 1 条 JWT 凭证。
- 返回的 API Key、SK 仅在本次响应中返回明文,请及时保存。
请求结构
Plain Text
1POST /?action=CreateConsumerAuthorizationInfo HTTP/1.1
2Host: apigw-control.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "consumerId": consumerId,
7 "authorizationType": authorizationType,
8 "apiKeyConfig": {
9 "createType": createType,
10 "apiKey": apiKey
11 },
12 "jwtConfig": {
13 "mode": mode,
14 "issuer": issuer,
15 "audience": audience,
16 "subject": subject,
17 "localJwks": {
18 "secretType": secretType,
19 "jwks": jwks
20 },
21 "remoteJwks": {
22 "uri": uri,
23 "port": port,
24 "refreshIntervalMs": refreshIntervalMs,
25 "fetchTimeoutMs": fetchTimeoutMs
26 },
27 "jwtTokenConfig": {
28 "position": position,
29 "key": key,
30 "prefix": prefix,
31 "pass": pass
32 },
33 "jwtPayloadConfig": {
34 "identifyClaim": identifyClaim,
35 "identifyClaimValue": identifyClaimValue
36 },
37 "claimsToHeaders": [
38 {
39 "claim": claim,
40 "header": header,
41 "overwrite": overwrite
42 }
43 ]
44 }
45}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| consumerId | String | 是 | RequestBody参数 | 消费者 ID |
| authorizationType | String | 是 | RequestBody参数 | 认证类型:API_KEY / AK_SK / JWT |
| apiKeyConfig | ApiKeyConfigReq | 否 | RequestBody参数 | API_KEY 专属配置,缺省等同 createType=System;其他类型必须为空 |
| jwtConfig | JwtConfigReq | 否 | RequestBody参数 | JWT 专属配置,JWT 时必填;其他类型必须为空 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| authorizationInfoId | String | 鉴权信息 ID,用于后续更新、删除 |
| authorizationType | String | 认证类型:API_KEY / AK_SK / JWT |
| apiKey | String | API Key 明文,仅 API_KEY 类型有值 |
| ak | String | Access Key 明文,仅 AK_SK 类型有值 |
| sk | String | Secret Key 明文,仅 AK_SK 类型有值,仅在本次响应中返回 |
| identifyClaim | String | JWT 身份识别 claim 名,仅 JWT 类型有值;未填写时为 uid |
| identifyClaimValue | String | JWT 身份识别 claim 值,仅 JWT 类型有值 |
错误码
| 错误码 | 错误描述 | HTTP 状态码 | 中文解释 |
|---|---|---|---|
| MethodArgumentNotValidException | MethodArgumentNotValidException: consumerId must not be blank | 400 | 必填参数缺失或格式不合法,consumerId 不能为空 |
| HttpMessageNotReadable | Http Message Not Readable: JSON parse error | 400 | 请求体不是合法 JSON,无法解析,请检查 JSON 语法和字段类型 |
| InvalidParameter.AuthorizationType | Authorization type is invalid. | 400 | 认证类型取值非法 |
| InvalidParameter.ApiKeyConfig | apiKeyConfig is only allowed for API_KEY authorization type. | 400 | 非 API_KEY 类型不允许传 apiKeyConfig |
| InvalidParameter.JwtConfig | jwtConfig is only allowed for JWT authorization type. | 400 | 非 JWT 类型不允许传 jwtConfig,或 JWT 配置不合法 |
| MissingParameter.JwtConfig | jwtConfig is required for JWT authorization type. | 400 | JWT 类型必须传 jwtConfig |
| QuotaExceeded.Resources | There can be a maximum of {quota} API Key. | 403 | API Key、AK/SK 或 JWT 凭证数量达到配额上限,{quota} 为实际配额值 |
| Consumer.NotFound | Consumer does not exist. | 404 | 消费者不存在、不属于当前账号或已删除 |
| Consumer.ApiKeyDuplicate | API Key already exists in this account. | 409 | API Key 已存在于当前账号下,请更换 |
| Consumer.JwtIdentityDuplicate | JWT identity already exists in this account. | 409 | JWT 身份标识(identifyClaim、identifyClaimValue)在当前账号内已存在 |
| HttpMediaTypeException | HttpMediaTypeException: Content-Type 'text/plain' is not supported | 415 | 请求的 Content-Type 不受支持,请使用 application/json |
| DataPlane.SyncFailed | Configuration was saved, but consumer authentication synchronization failed. | 500 | 配置已保存,但消费者认证配置同步失败,请稍后重新保存该凭证重试或联系技术支持 |
请求示例
Plain Text
1POST /?action=CreateConsumerAuthorizationInfo HTTP/1.1
2Host: apigw-control.bj.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2015-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
4
5{
6 "consumerId": "consumer-a1b2c3d4",
7 "authorizationType": "API_KEY",
8 "apiKeyConfig": {
9 "createType": "System"
10 }
11}
返回示例
Plain Text
1HTTP/1.1 200 OK
2x-bce-request-id: 1214cca7-4ad5-451d-9215-71cb844c0a50
3Date: Wed, 03 Dec 2014 06:42:19 GMT
4Content-Type: application/json;charset=UTF-8
5Server: BWS
6
7{
8 "authorizationInfoId": "authorization_info-m3n4o5p6",
9 "authorizationType": "API_KEY",
10 "apiKey": "ak-3f8e2d1c9b7a4e6f",
11 "ak": "",
12 "sk": ""
13}
评价此篇文章
