Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added timeout logic as per multiple requests
- Loading branch information
1 parent
39859a1
commit 22fe7f6
Showing
5 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
$config['jwt_key'] = 'ingDLMRuGe9UKHRNjs7cYckS2yul4lc3'; | ||
$config['jwt_key'] = 'ingDLMRuGe9UKHRNjs7cYckS2yul4lc3'; | ||
|
||
/*Generated token will expire in 1 minute for sample code | ||
* Increase this value as per requirement for production | ||
*/ | ||
$config['token_timeout'] = 1; | ||
|
||
/* End of file jwt.php */ | ||
/* Location: ./application/config/jwt.php */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
defined('BASEPATH') OR exit('No direct script access allowed'); | ||
|
||
require APPPATH . '/libraries/REST_Controller.php'; | ||
|
||
/* | ||
* Changes: | ||
* 1. This project contains .htaccess file for windows machine. | ||
* Please update as per your requirements. | ||
* Samples (Win/Linux): http://stackoverflow.com/questions/28525870/removing-index-php-from-url-in-codeigniter-on-mandriva | ||
* | ||
* 2. Change 'encryption_key' in application\config\config.php | ||
* Link for encryption_key: http://jeffreybarke.net/tools/codeigniter-encryption-key-generator/ | ||
* | ||
* 3. Change 'jwt_key' in application\config\jwt.php | ||
* 3. Change 'token_timeout' in application\config\jwt.php | ||
* | ||
*/ | ||
|
||
class Authtimeout extends REST_Controller | ||
{ | ||
/** | ||
* URL: http://localhost/CodeIgniter-JWT-Sample/authtimeout/token | ||
* Method: GET | ||
*/ | ||
public function token_get() | ||
{ | ||
$tokenData = array(); | ||
$tokenData['id'] = 1; //TODO: Replace with data for token | ||
|
||
/* Date helper | ||
* https://www.codeigniter.com/user_guide/helpers/date_helper.html | ||
* Added helper "date" in application\config\autoload.php line 92 | ||
* Notice - 'timestamp' is part of $tokenData | ||
*/ | ||
$tokenData['timestamp'] = now(); | ||
|
||
$output['token'] = AUTHORIZATION::generateToken($tokenData); | ||
$this->set_response($output, REST_Controller::HTTP_OK); | ||
} | ||
|
||
/** | ||
* URL: http://localhost/CodeIgniter-JWT-Sample/authtimeout/token | ||
* Method: POST | ||
* Header Key: Authorization | ||
* Value: Auth token generated in GET call | ||
*/ | ||
public function token_post() | ||
{ | ||
$headers = $this->input->request_headers(); | ||
if (array_key_exists('Authorization', $headers) && !empty($headers['Authorization'])) { | ||
//TODO: Change 'token_timeout' in application\config\jwt.php | ||
$decodedToken = AUTHORIZATION::validateTimestamp($headers['Authorization']); | ||
|
||
// return response if token is valid | ||
if ($decodedToken != false) { | ||
$this->set_response($decodedToken, REST_Controller::HTTP_OK); | ||
return; | ||
} | ||
} | ||
|
||
$this->set_response("Unauthorised", REST_Controller::HTTP_UNAUTHORIZED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters