2

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.

Andrew Ferrier
  • 16,664
  • 13
  • 47
  • 76
Vivek
  • 680
  • 1
  • 12
  • 24
  • This is a great question, and I applaud the approach you're taking. HTTP 405 normally means "Method not allowed", which means (for example) you're using GET where you should be using PUT, or PUT rather POST, or similar. What verb are you using in PostMan? What verb are you using from within your NodeJS test. Can you share a snippet of code? – Andrew Ferrier Oct 07 '15 at 08:00
  • 1
    Thanks. I found the problem. I was sending a GET request. Changed it to POST and it is working now. – Vivek Oct 07 '15 at 09:16
  • Excellent, and thanks for posting your code too - could be a useful example for others. – Andrew Ferrier Oct 07 '15 at 10:33

1 Answers1

1

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.

Vivek
  • 680
  • 1
  • 12
  • 24