I am creating an app for Magento 2 but there is no any API for a customer to check if user/customer is authenticated or not. Followed : http://devdocs.magento.com/swagger/index.html#/
But there is not any solution.
I am creating an app for Magento 2 but there is no any API for a customer to check if user/customer is authenticated or not. Followed : http://devdocs.magento.com/swagger/index.html#/
But there is not any solution.
You should use this API:
integrationCustomerTokenServiceV1:
Interface providing token generation for Customers
POST /V1/integration/customer/toke
http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html
you can use the authenticate function in accountmanagerinterface. in your webapi.xml file include this code.
<route url="/V1/customers/authenticate/:email/:password" method="GET">
<service class="Magento\Customer\Api\AccountManagementInterface" method="authenticate"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
you can call this via curl in php.
$userData = array("username" => "your_username", "password" => "your_password");
$ch = curl_init("http://localhost/magento/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-Lenght: " . strlen(json_encode($userData))));
$token = curl_exec($ch);
$ch = curl_init("http://localhost/magento/index.php/rest/V1/customers/authenticate/".
"[email protected]". //username/email
"/".
"[email protected]" //password
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$result = curl_exec($ch);
echo($result);
For creating an App in MAgento 2, you can follow the REST API for a customer to authenticate.
For Customer Token: Magento grants access to resources with the anonymous or self permission.
Use the API: Endpoint: POST /rest/<store_code>/V1/integration/customer/token
Soap: integrationCustomerTokenServiceV1
For full details please check: https://www.cloudways.com/blog/magento-2-rest-api/