Get JWT Token Create JWT token for authentication using JWT (added in v 1.3)

You can create JWT token using the RESTp API. You need to pass the required details e.g username and password to be validated and it returns the JWT token. You can also set expiry time, password encryption method etc. in config file.

  
                                //Dummy data to insert.
                                $data = array("data" => array("email" =>  "test@gmail.com", "password" => "1234"));
                                //Option 1: Convert data array to json if you want to send data as json
                                $data = json_encode($data);
                                /****** curl code ****/
                                //init curl
                                $ch = curl_init();
                                // URL to be called
                                curl_setopt($ch, CURLOPT_URL, "http://pdocrud.com/RESTP/api/users/?op=jwtauth");
                                //set post TRUE to do a regular HTTP POST
                                curl_setopt($ch, CURLOPT_POST, 1);
                                //set http headers - if you are sending as json data (i.e. option 1) else comment this 
                                curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
                                //send post data
                                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                                //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({
                                        type: "post",
                                        url: "http://pdocrud.com/RESTP/api/users/?op=jwtauth",
                                        data : {data:{email: "test@gmail.com",
                                                password:"1234"
                                        }},
                                        success: function (response) {
                                            console.log(response);
                                            jQuery("#js_output").text(response);
                                        }
                                    });
                                });
                            });