1
I’m creating an application with Laravel, which consists of consuming the Mcafee API.
The previous version was built in pure php, from which it consumed the data of a Mysql database powered by a Nodejs script that consumed the API.
The point is, the API requires authentication to consume the data, which was done with the Axios Auth method as below:
import axios from 'axios';
import https from 'https';
import sequelize from 'sequelize';
class requisitionController {
async store(req, res) {
try {
const agent = new https.Agent({
rejectUnauthorized: false
});
const response = await axios.get('https://ePODirectory:port/remote/core.executeQuery?target=EPOLeafNode&select=(select%20EPOComputerProperties.ComputerName%20EPOComputerProperties.IPAddress%20EPOLeafNode.LastUpdate%20EPOComputerProperties.OSType%20EPOLeafNode.ManagedState%20EPOProdPropsView_EPOAGENT.productversion%20EPOProdPropsView_VIRUSCAN.datver)%22&:output=json', {
httpsAgent: agent,
auth: {
username: '*********',
password: '*********'
}
});
const responseJSON = JSON.parse(response.data.replace('OK:', ''));
return res.json(responseJSON);
} catch(err) {
return res.json(err);
}
}
}
export default new requisitionController();
My question is, is it possible to consume this API with PHP/Laravel by performing this authentication?
Thank you in advance :-)
It is possible yes, you will use the
guzzlehttp/guzzle
to communicate with the destination API and on the route call you will pass the authentication parameters that the API needs.– Kayo Bruno