Home > Software design >  How to disable SSL certificate verification while post request in react JS?
How to disable SSL certificate verification while post request in react JS?

Time:10-20

I am trying to use keycloack for user authentication, I need to disable SSL verification for some testing purpose. In postman it works well if I disable SSL certificate verification. But in my react JS code it is giving me and error (net::ERR_CERT_AUTHORITY_INVALID) even it is disabled as shown in below code. Kindly correct me if anything missing in the below code or any else need to do.

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("grant_type", "password");
urlencoded.append("client_id", "clientid");
urlencoded.append("username", "username");
urlencoded.append("password", "password");
urlencoded.append("client_secret", "clientsecret");

const httpsAgent = new https.Agent({
    rejectUnauthorized: false,
  });

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow',
  Agent: httpsAgent
  
};

fetch("serverurl/realms/realmname/protocol/openid-connect/token", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

ERROR: net::ERR_CERT_AUTHORITY_INVALID

CodePudding user response:

As I got a workaround,

Just enter the request URL in the browser and if getting trust error, just click on Advanced and go with unsafe to load the request, it may required at least 3 attempts to do the same then page will load. and try the same request through react app then it will not give you such SSL error.

  • Related