daily pastebin goal
9%
SHARE
TWEET

php_jwt_generation

a guest Mar 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     function route($method, $data, $dataArray) {
  3.         $user_info = json_decode(file_get_contents("php://input"), true);
  4.         $salt = "228";
  5.         $response = array();
  6.  
  7.         if (strcmp($user_info["login"], "admin") === 0 && strcmp($user_info["password"], "admin") === 0) {
  8.             header("HTTP/1.1 200 Successfull Authorization");
  9.             $token_header = json_encode(array(
  10.                 "alg" => "HS256",
  11.                 "typ" => "JWT"
  12.             ));
  13.  
  14.             $token_payload = json_encode(array(
  15.                 "role" => "admin"
  16.             ));
  17.  
  18.             $token_signature = hash_hmac('sha256',
  19.                                 base64_encode($token_header) .
  20.                                 "." .
  21.                                 base64_encode($token_payload),
  22.                                 $salt  
  23.             );
  24.  
  25.             $response["token"] = base64_encode($token_header) .
  26.                                                         "." .
  27.                                                         base64_encode($token_payload) .
  28.                                                         "." .
  29.                                                         base64_encode($token_signature);
  30.             echo json_encode($response);
  31.         }
  32.     }
  33. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top