Server 1 = http://localhost:7000
hmac.php
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Headers: X-ACCESS_TOKEN, Origin, Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
$getheaders = getallheaders();
$secretKey = '8uRhAeH89naXfFXKGOEj';
$value = 'username=rasmuslerdorf';
$signature = $getheaders['Authorization'];
if (hash_equals(hash_hmac('sha256', $value, $secretKey), $signature)) {
echo json_encode("The value is correctly signed.");
} else {
echo json_encode("The value was tampered with.");
}
?>
Server 1 = http://localhost:9000
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<script>
window.addEventListener("load", async () => {
await callData();
})
function callData() {
fetch('http://localhost:7000/hmac.php', {
method: 'GET',
headers: {
'Authorization': '8c35009d3b50caf7f5d2c1e031842e6b7823a1bb781d33c5237cd27b57b5f327'
}
})
.then(response => response.json())
.then(data => {
console.log(data)
})
}
</script>
</html>
No comments:
Post a Comment