0

I am creating a serverless app using IBM Cloud Functions. My Cloud Functions API is secured with OAuth user authentication using an IBM Cloud App ID service. When a user logs into my app, an access token is generated by this service. I want to extract user data from that access token so that I can customize the user experience.

How do I access that token from within a Cloud Functions action that is coded for Node.js 10?

Example
The openwhisk webaction doc
https://github.com/apache/openwhisk/blob/master/docs/webactions.md
states that the following code

function main(params) {
    return { response: params };
}

generates the following response

{
  "response": {
    "__ow_method": "get",
    "__ow_headers": {
      "accept": "*/*",
      "connection": "close",
      "host": "172.17.0.1",
      "user-agent": "curl/7.43.0"
    },
    "__ow_path": ""
  }
}

From that data I should be able to get HTTP request details. Specifically, I should be able to get the Authorization header value off the "__ow_headers" property of the action argument (params).

However, the same code inside an IBM Cloud Functions web action generates nothing. Nothing exists on the params object.

  • The http header is available which should include auth info: https://cloud.ibm.com/docs/openwhisk?topic=cloud-functions-actions_web#actions_web_context Not sure if it applies to your way of authenticating users. – data_henrik Dec 13 '19 at 08:50
  • @data_henrik, thank you. Your link demonstrates that what I want to do is possible. But I haven't been able to do it. I expected that the action argument (params) should be injected with properties (like "__ow_headers") that hold the HTTP request details. However, I return that argument (params) and I get nothing out of it. – jahoward11 Dec 14 '19 at 04:02
  • @data_henrik, because of your tip I discovered my mistake and answered my own question. In an IBM Cloud Functions web action the params object does have the HTTP request details as documented. But, in order to confirm that with a get request, the return object should have a *body* property -- i.e.,` return { body: params };`. Thanks again. – jahoward11 Dec 17 '19 at 02:08

0 Answers0