0

I'm trying to develop a service using nodeJS that retrieve a token OAuth from a server. But I have every time an error. this the function.

var express = require('express')
var http = require('http');
var httpRequest = require('request');
var bodyParser = require('body-parser');
var app = express()

app.get('/get-token', function (request, response) {

  // Ask for token
  httpRequest({
      url: 'https://my-server.com/token',
      method: 'POST',
      headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Authorization': 'Basic SdfdhffhPeHVBTV84OExfVWFmR1cwMklh'
      },
      form: {
        'grant_type': 'password',
        'username': 'myLogin',
        'password': 'myPwd',
      }
    }, function(error, response, body){
      if(error) {
          console.log(error);
      } else {
          console.log(response.statusCode, body);
      }
  });

});

When I make a request, the server return this error:

{ [Error: unable to verify the first certificate] code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

Would you have an idea how I can process or if there is a package npm that make the same job ?

Best regards

Amine Hatim
  • 237
  • 2
  • 7
  • 19

1 Answers1

0

This wokrks for me

...  
  app.get('/get-token', function (request, response) {

      // Ask for token
      httpRequest({
          rejectUnauthorized: false,
          url: 'https://my-server.com/token',
     ...
Amine Hatim
  • 237
  • 2
  • 7
  • 19