You can check authentication using JWT. It validates the passed JWT string using the secret code set in config. If it valid string, then it returns true and allow access else send unauthorized message.Please note that it doesn't generate the JWT string. JWT string is sent using the Authorization header.
Please note that you need to enable JWT authentication in config file to make it work. You can also set secret key and allowed algorithm in config file. More details about JWT, click here. It uses the php-jwt-master library to validated JWT.
//init curl $ch = curl_init(); // URL to be called i.e. end point to access resource. // e.g. Get all records of a database table name "orders". curl_setopt($ch, CURLOPT_URL, "http://pdocrud.com/RESTP/api/orders/"); //return as output instead of printing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //execute curl request $result = curl_exec($ch); //close curl connection curl_close($ch); //print result print_r($result);
jQuery(document).ready(function () { jQuery.ajax({ beforeSend: function (xhr){ xhr.setRequestHeader('Authorization', "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9leGFtcGxlLm9yZyIsImF1ZCI6Imh0dHA6XC9cL2V4YW1wbGUuY29tIiwiaWF0IjoxMzU2OTk5NTI0LCJuYmYiOjEzNTcwMDAwMDB9.Vzzn07mgNjPCJ3Gylx-HGsYSgFDlu4K_VO_3oY2UWkk"); }, url: "http://pdocrud.com/RESTP/api/orders/", success: function (response) { console.log(response); jQuery("#js_output").text(response); } }); });