I am using REST API in Magento 2. For using in Guest user i want to create admin token so i have used CURL Request like this.
$ch = curl_init(); $userData = array("username" => "admin", "password" => "password"); $ch = curl_init("http://127.0.0.1/mag/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);
and $token is generated.
But I have a question regarding this that it it safe to use this in my Controller file if yes then it is good or not please suggest any other solution.
Token Generated from ADMIN
Any help is appriciated.