Hi
I want to do certificate based authentication in React Native, for that I am using Rest API.
And from the docs https://zcusa.951200.xyz/en-us/azure/iot-dps/how-to-control-access#certificate-based-authentication I found out this cURL, and I need to send certificate and key file in API, as https.agent is not supported by React Native, how can I manage to do that?
curl -L -i -X PUT –cert ./[device_cert].pem –key ./[device_cert_private_key].pem -H 'Content-Type: application/json' -H 'Content-Encoding: utf-8' -d '{"registrationId": "[registration_id]"}' https://global.azure-devices-provisioning.net/[ID_Scope]/registrations/[registration_id]/register?api-version=2021-06-01
So far what I have tried is
const data = {
registrationId: registrationId,
};
const cert = await RNFS.readFile(certificatePath, 'utf8');
const key = await RNFS.readFile(keyPath, 'utf8');
console.log('cert', cert);
console.log('key', key);
try {
const httpsAgent = new https.Agent({
cert: cert,
key: key,
keepAlive: true,
});
console.log('httpsAgent', httpsAgent);
const response = await axios({
method: 'PUT',
url: `https://global.azure-devices-provisioning.net/${scopeId}/registrations/${registrationId}/register?api-version=2021-06-01`,
data: data,
httpsAgent: httpsAgent,
headers: {
'Content-Type': 'application/json',
'Content-Encoding': 'utf-8',
},
});
return response.data;
} catch (err) {
console.log('err', err);
return err;
}
Thank you!!!