Request-Promise throws "undefined authorization mechanism" using async / await

I was just trying to asynchronously / wait with request-promise

and ran into this error:

RequestError: Error: no auth mechanism defined
      at new RequestError (node_modules/request-promise-core/lib/errors.js:14:15)
      at Request.plumbing.callback (node_modules/request-promise-core/lib/plumbing.js:87:29)
      at Request.RP$callback [as _callback] (node_modules/request-promise-core/lib/plumbing.js:46:31)
      at self.callback (node_modules/request/request.js:188:22)
      at Auth.onRequest (node_modules/request/lib/auth.js:133:18)
      at Request.auth (node_modules/request/request.js:1360:14)
      at Context.<anonymous> (test/routes.js:37:41)
  From previous event:
      at Request.plumbing.init (node_modules/request-promise-core/lib/plumbing.js:36:28)
      at Request.RP$initInterceptor [as init] (node_modules/request-promise-core/configure/request2.js:41:27)
      at new Request (node_modules/request/request.js:130:8)
      at request (node_modules/request/index.js:54:10)
      at Context.<anonymous> (test/routes.js:37:24)

      

This is an API endpoint I recently created that needed to create a new user in MongoDB. It uses Basic Auth provided by the Passport strategy, and I tested with Postman that it works. I am not entirely sure why this error occurs.

My request code (using Mocha):

it("creates a new user", async () => {
  const options = {
    method: "POST",
    uri: `http://localhost:${process.env.PORT}/api/users`,
    headers: {
      "User-Agent": "Request-Promise",
      "Content-Type": "application/json"
    },
    body: {
      email: "test@domain.com",
      password: "password",
      firstName: "John",
      lastName: "Smith"
    },
    json: true
  };
  const resp = await request(options).auth(APP_ID, SIGNATURE, false);
  expect(resp).to.be.an("object");
});

      

Edit: I must also add that I am using node 8.2.1 and npm 5.3.0.

+3


source to share


1 answer


This is usually caused by not providing the appropriate credentials. The code causing the error can be found here . Have you confirmed that APP_ID

and SIGNATURE

are not undefined

in your test?



0


source







All Articles