issue token $method = $_SERVER['REQUEST_METHOD']; $body = json_decode(file_get_contents('php://input'), true) ?: []; if ($method === 'POST' && isset($body['action']) && $body['action'] === 'login') { $u = $body['username'] ?? ''; $p = $body['password'] ?? ''; // plaintext check — admin / admin123 if ($u === 'admin' && $p === 'admin123') { $jwt = sign( json_encode(['alg' => 'HS256', 'typ' => 'JWT']), json_encode(['sub' => 'admin', 'role' => 'admin', 'iat' => time(), 'exp' => time() + 3600]), $SECRET ); echo json_encode(['token' => $jwt, 'expires_in' => 3600]); exit; } http_response_code(401); echo json_encode(['error' => 'bad credentials']); exit; } // GET — show current session from Authorization: Bearer ... $hdr = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; if (preg_match('/Bearer\s+(\S+)/i', $hdr, $m)) { $claims = verify($m[1], $SECRET); if ($claims) { echo json_encode(['authenticated' => true, 'claims' => $claims]); exit; } http_response_code(401); echo json_encode(['error' => 'invalid token']); exit; } echo json_encode([ 'message' => 'POST {action:"login",username,password} to obtain token', 'example' => ['username' => 'admin', 'password' => 'admin123'], ]);