How to generate an IBM Cloud token from an API Key

359 views Asked by At

I have generated an API key for IBM Cloud, how do I programmatically generate a token from the API key?

1

There are 1 answers

0
Jeff Sloyer On BEST ANSWER

Here is a curl request to do that.

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'

Replace xxx with your API key.

The basic authorization is base64 encoded with a username of bx and a password of bx.

The response looks like the following:

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