I'm testing the REST API of magento.
According to the docs: "To make a web API call from a client such as a mobile application, you must supply an access token on the call."
I can successfully get the token for my admin account using the code below.
$userData = array("username" => "admin", "password" => "...");
$ch = curl_init("http://localhost/magento2/index.php/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Length: " . strlen(json_encode($userData))));
$token = curl_exec($ch);
Strangely, I can call the REST API even without using the token like so:
curl -H "Content-Type: application/json" -X POST -d '{"customer": {"email": "[email protected]", "firstname": "Test", "lastname": "Customer"}}' http://localhost/magento2/index.php/rest/V1/customers
No token is used in this call, however the customer is still created. Why does the REST API of my magento API not require credentials and how do I change this?