I am trying to fetch oauth token in NodeJS with key , certificate & client id.
Code for the same:
var form = {
client_id : CLIENT_ID,
grant_type: 'client_credentials',
}
var headers= {
'content-type': 'application/x-www-form-urlencoded',
}
var option = {
method: 'POST',
url: CERTIFICATE_URL "/oauth/token",
headers,
form,
httpsAgent:new https.Agent({
cert: CLIENT_CERTIFICATE.replace(/\\n/g, '\n'),
key: CLIENT_CERTIFICATE_KEY.replace(/\\n/g, '\n')
})
};
request(option, function(error, response, body) {
var token = null;
console.log(error);
console.log(JSON.parse(body).access_token)
if(!error && response.statusCode == 200) {
token = JSON.parse(body).access_token;
} else {
console.log(error)
error = error | new Error(body);
}
cb(error, token);
});
But getting the following error : Error: write EPROTO 140062523283264:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 40 2021-10-13T23:46:56.23 0530 [APP/PROC/WEB/0] OUT at WriteWrap.afterWrite [as oncomplete] (net.js:789:14) errno: 'EPROTO', code: 'EPROTO', syscall: 'write'
The certificate & key is generated & fetched from the cloud environment itself. This is a x509 MTLS based authentication.
CodePudding user response:
Was able to do it with axios library, request library seems to be deprecated.