Created
May 19, 2019 04:42
-
-
Save rlcc885/c3fb604bd9b6b6b539fb75a3964635a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| require('vendor/autoload.php'); | |
| use \Firebase\JWT\JWT; | |
| class ImplementJwt { | |
| //////////The function generate token///////////// | |
| PRIVATE $key = "uEsHptabPr3qIjjyFrOK2G7PMbh82Czi"; | |
| public function GenerateToken($data) { | |
| $jwt = JWT::encode($data, $this->key); | |
| return $jwt; | |
| } | |
| //////This function decode the token//////////////////// | |
| public function DecodeToken($token) { | |
| $decoded = JWT::decode($token, $this->key, array('HS256')); | |
| $decodedData = (array) $decoded; | |
| return $decodedData; | |
| } | |
| } | |
| //echo 'hola'; | |
| header('Content-Type: application/json'); | |
| $myJWT = new ImplementJwt(); | |
| $tokenData['uniqueId'] = '55555'; | |
| $tokenData['role'] = 'admin'; | |
| $tokenData['timeStamp'] = Date('Y-m-d h:i:s'); | |
| $jwtToken = $myJWT->GenerateToken($tokenData); | |
| //echo json_encode(array('Token'=>$jwtToken)); | |
| $arr_token = array('Token'=>$jwtToken); | |
| //$received_Token = $this->input->request_headers('Authorization'); | |
| try { | |
| $jwtData = $myJWT->DecodeToken($arr_token['Token']); | |
| echo json_encode($jwtData); | |
| } catch (Exception $e) { | |
| http_response_code('401'); | |
| echo json_encode(array( "status" => false, "message" => $e->getMessage()));exit; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment