API参考
更新时间:2025-01-16
创建API Key(短期)
权限说明
创建API Key(短期)接口受到权限管控,请先授权子用户:IAMManageAPIKeyPolicy,授权请参考:子用户授权
接口描述
此接口为原创建BearToken接口
创建一个短期API Key,具有和长效API Key相同的功能,支持指定短期API Key的有效时间
Authorization头,除使用AccessKey和SecretKey生成签名外,也支持使用长效API Key作为认证Token,如 Authorization: Bearer{API Key}
- 如使用长效API Key作为认证请求头,短期API Key的权限范围等同于长效API Key的权限
- 如使用AccessKey和SecretKey生成签名换取短期API Key,默认具有所有权限;同时,接口支持指定额外的ACL进一步控制权限,示例如下:
ACL示例
{
"version": "v2",
"id": "GNHenkTSBBmnhoNNaRRaz",
"accessControlList": [{
"service": "bce:ai_apaas",
"region": "global",
"resource": ["app/46484bef-3fe4-4b15-96fc-01bd6e0e6217"],
"resource_owner": "USE_REQUESTER_ACCOUNTID",
"permission": ["UseApp", "ReadApp"],
"effect": "Allow"
}]
}
请求结构
GET /v1/BCE-BEARER/token HTTP/1.1
Host: iam.bj.baidubce.com
Authorization: authorization string
请求头域
除公共头域(详见认证机制说明)外,无其它特殊头域。
请求参数
名称 | 类型 | 位置 | 描述 | 是否必须 |
---|---|---|---|---|
expireInSeconds | Integer | 查询参数 | 有效时长,单位为秒。最长86400。若不指定,则默认为86400,即1天 | 否 |
acl | String | 查询参数 | 额外指定的acl的base64 | 否 |
响应头域
除公共头域(详见认证机制说明)外,无其它特殊头域。
响应参数
请求示例
GET /v1/BCE-BEARER/token?expireInSeconds=1800&acl=eyJpZCI6ImlWRVRhV2tFdnB2ODd2dXZ2TGF2UiIsImFjY2Vzc0NvbnRyb2xMaXN0IjpbeyJzZXJ2aWNlIjoiYmNlOndlbnhpbmZhY3RvcnkiLCJyZWdpb24iOiIqIiwicmVzb3VyY2UiOlsiYXBwL3Rlc3RBbGxvdyJdLCJwZXJtaXNzaW9uIjpbIioiXSwiZWZmZWN0IjoiQWxsb3cifV0sInZlcnNpb24iOiJ2MiJ9== HTTP/1.1
Host: iam.bj.baidubce.com
content-type: application/json
Authorization: AuthorizationString
响应示例
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
X-Bce-Request-Id: 8d51a788-e79d-4ced-a9e0-0662ec85b7f7
Server: BWS
{
"userId": "6f0e6521add2485298f3931308d26eee",
"token": "bce-v3/ALTAK-jvNWHUJVrboWzT81U3IbK/6b0e29b18deb12f996a113eec8159f6135fa84a4;ODgzNjk4N2NiNzZjNGI2NjhhYjBhMDY1NzRhM2M1ODR8AAAAAIsCAAApYCxVsG0rRjd8ByqEyC6/DHy+ZiTSp/NhkOzGzsoaLQwMWpOp+BH1Fni7duY1JZ6jHgnL/xUOxxJ97HI6aMwRvhoGKxWESYkAAcBy3k12r/O525xgfgJJFQ4wYkmCDYJLYIcmzp2mDL1d9ozYGgcreHrIeSPYFvtkSomqh5NvCMkBYok0LZUzMiBL4tDcjfTcfuj3tikOpVqTdmx6pByHa8VrIIIwnvyZgF8xPi2870nEagWVLdsyffyxvj+BEAwGW/UUwJa1swVRCPQpi6Kkrn2vgV4DKCqXKGKslvke3cBIH7iPzEtjJvyu0xdI6FDgfurW1NIAlM7zrRs9T9vth+ovHWsPo/pawX8MFGB7SNCmOIwiECLousbIRjSWEFKyGSgam5o2kW4RFsHLJJXodBH7hiL8krqp3NOHw8fPRhu5Gc43AVV3GvfQwDVHx5tCeqdq3Xug0Mb5ObuqI9ZR1Ctm1F8VSWzF3Eh/jI3I9wqqgEGGR9q4TbOOG3cwJR7uTm2hZijpiBakLM2BESUTg51Po1XZpO56cw2jjlNjfu/WoKVH9BSUEp3A22ooct8=",
"createTime": "2025-01-09T06:37:08.571Z",
"expireTime": "2025-01-10T06:37:08.571Z"
}