-1

My question is a follow up of Do I need a paid plan for using recaptcha on firebase function?

I find myself in the same situation : I need to use firebase cloud function with Google Recaptcha API. Still, I encounter the getaddrinfo enotfound error.

Here is my code :

exports.checkRecaptcha =  functions.https.onRequest((req, res) => {

  res.set('Access-Control-Allow-Origin', "*")
  res.set('Access-Control-Allow-Methods', 'GET, POST')

const request = require('request');
const got = require('got');
      var requestQuery = req.query; 
      var secret_key = '---------';

      if( requestQuery != undefined && requestQuery != '' && requestQuery != null && requestQuery.response != undefined && requestQuery.response != '' && requestQuery.response != null ){
          var response = requestQuery.response;   

              got('recaptcha.google.com/recaptcha/api/siteverify?secret='+ secret_key +'&response=' +response, { json: true }).then(response => {
                console.log(response);
                res.status(200).send("");
              }).catch(error => {
                console.log(error);
                res.status(500).send(error);
              });


      }else{
          res.send({"responseCode" : 1,"responseDesc" : "Failed captcha verification=> FOIRAGE"});
      }

});

According to Doug Stevenson, reCAPTCHA server API has been whitelisted, so I should be able to access it with my cloud function, yet I do not.

Raphael St
  • 661
  • 8
  • 23

1 Answers1

0

When fetching URLs in Cloud Functions, you should be using a full URL that specifies the scheme of the endpoint. Google endpoints always require HTTPS, which is a secure version of HTTP.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441