Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function route($method, $data, $dataArray) {
- $user_info = json_decode(file_get_contents("php://input"), true);
- $salt = "228";
- $response = array();
- if (strcmp($user_info["login"], "admin") === 0 && strcmp($user_info["password"], "admin") === 0) {
- header("HTTP/1.1 200 Successfull Authorization");
- $token_header = json_encode(array(
- "alg" => "HS256",
- "typ" => "JWT"
- ));
- $token_payload = json_encode(array(
- "role" => "admin"
- ));
- $token_signature = hash_hmac('sha256',
- base64_encode($token_header) .
- "." .
- base64_encode($token_payload),
- $salt
- );
- $response["token"] = base64_encode($token_header) .
- "." .
- base64_encode($token_payload) .
- "." .
- base64_encode($token_signature);
- echo json_encode($response);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement