I'm having trouble figuring out how I could authenticate and authorize a IBM Cloud Function to use the IBM Cloud Foundry API to manage some routes on one of my Cloud Foundry apps.
The Cloud Foundry API says I'll need a valid bearer token, and that I can get a token using the Cloud Foundry UAA server. I don't think using OAuth2 fits for my use case because I am not accessing anyone else's resources on their behalf.
How can I authenticate & authorize my Cloud Function to access the Cloud Foundry API?
EDIT:
I just found Generating an IBM Cloud IAM token by using an API key. Is an IAM token compatible with the Cloud Foundry API? I see in this document that the https response describes the token type as Bearer
.
I can't guide you the full way right now, but I hope the information that I can provide will guide you into the right direction.
First you'll need to identify the authorization endpoint:
curl http://api.us-south.cf.cloud.ibm.com/info
With that and a valid IAM API token for your account you can get the bearer token that will work against the IBM Cloud CF Public API:
curl -v -X POST "https://iam.cloud.ibm.com/cloudfoundry/login/us-south/oauth/token" -d "grant_type=password&scope=&username=apikey&password=<yourApiKey>" --user "cf:"
Note that you need to append
/oauth/token
to the authorization endpoint that you received in step 1.The response contains the access token that you need. For this example, just put it into an environment variable:
export TOKEN=<yourAccessToken>
Next try a command against the IBM Cloud CF Public API:
curl "https://api.us-south.cf.cloud.ibm.com/v2/organizations" -X GET -H "Authorization: bearer $TOKEN"
I hope once you have followed these steps in your command line, you will be able to do the same steps in your IBM Cloud Function and you'll reach your goal.