-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_request.php
More file actions
55 lines (41 loc) · 1.48 KB
/
get_request.php
File metadata and controls
55 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
include("config.php");
require __DIR__ . '/vendor/autoload.php';
use \Firebase\JWT\JWT;
/*
foreach (getallheaders() as $name => $value) {
echo "$name: $value\n";
}*/
$allHeaders = getallheaders();
$authorization = $allHeaders['Authorization'];
list($jwt) = sscanf( $authorization, 'Bearer %s');
if($jwt) {
try {
$secretKey = base64_decode($config['jwtKey']);
$token = JWT::decode($jwt, $secretKey, array('HS512'));
// print_r($token);
//$asset = base64_encode(file_get_contents('http://thewebfort.com/wp-content/uploads/2016/12/linear_logo.png'));
/*
* return protected asset
*/
$asset ="Iloveyou";
header('Content-type: application/json');
echo json_encode([
'img' => $asset
]);
} catch (Exception $e) {
/*
* the token was not able to be decoded.
* this is likely because the signature was not able to be verified (tampered token)
*/
// print_r($e);
header('HTTP/1.0 401 Unauthorized');
}
} else {
/*
* No token was able to be extracted from the authorization header
*/
header('HTTP/1.0 400 Bad Request');
}
//print_r($jwt);
?>