1. Go to this page and download the library: Download sprintcube/cakephp-rest library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* login method
*
* @return Response|void
*/
public function login()
{
// you user authentication code will go here, you can compare the user with the database or whatever
$payload = [
'id' => "Your User's ID",
'other' => "Some other data"
];
$token = \Rest\Utility\JwtToken::generate($payload);
$this->set(compact('token'));
}
return [
'Rest' => [
'jwt' => [
'key' => 'PUT YOUR KEY HERE', // it should contain alphanumeric string with symbols
'algorithm' => 'HS256' // See https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
]
]
];
/**
* view method
*
* @return Response|void
*/
public function view()
{
$token = $this->token;
$payload = $this->payload;
// your action logic...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.