Search code examples
node.jsunit-testingoauthibm-mobilefirstmobilefirst-adapters

Unit testing MobileFirst Platform Java Adapters with OAuth using NodeJS


I am writing a NodeJS application to test the IBM MobileFirst Platform adapters that I have written. The approach I want to follow to do this, as follows:

  1. Get a test token from the http://localhost:10080/AppName/authorization/v1/testtoken
  2. Use this Bearer token to make authenticated requests to my protected adapters.

The problem with approach is that, when I try to make a request to the testtoken end point, I am getting an HTTP 405 status error. However, the same works with PostMan.

Is there a way to make this work in the NodeJS application? I am using Request to send requests to the MobileFirst Server.

I am writing my NodeJS application using SailsJs.


Solution

  • The test token operation requires POST request.

    request.post('http://localhost:10080/app/authorization/v1/testtoken', function(error, response, body) {
            console.log(response.statusCode);
            if(!error && response.statusCode == 200) {
                console.log(body);
                return res.ok(body);
            } else {
                return res.notFound(error);
            }
        });
    

    In my case, I was using Request so the above code worked.