如何从API密钥生成IBM Cloud令牌

时间:2020-02-06 22:29:08

标签: ibm-cloud ibm-cloud-infrastructure ibm-cloud-kubernetes ibm-cloud-iam

我已经为IBM Cloud生成了API密钥,如何以编程方式从API密钥生成令牌?

1 个答案:

答案 0 :(得分:3)

这是一个卷曲请求。

curl --location --request POST 'https://iam.cloud.ibm.com/identity/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic Yng6Yng=' \
--data-urlencode 'apikey=xxx' \
--data-urlencode 'response_type=cloud_iam' \
--data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey'

用您的API密钥替换xxx

基本授权是使用用户名bx和密码bx进行编码的base64。

响应如下所示:

{
    "access_token": "bearer token",
    "refresh_token": "refresh token",
    "token_type": "Bearer",
    "expires_in": 3600,
    "expiration": 1581031424,
    "scope": "ibm openid"
}