v2.php
1.43 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
56
57
58
<?php
# $id = $_GET["id"];
# $type = $_GET["type"];
# $start = $_GET["start"];
$url = 'https://api.researchmap.jp/oauth2/token';
$client_key = '/home/ec2-user/.ssh/rmap_client_id.key';
$private_key = '/home/ec2-user/.ssh/rmap_jwt_private.key';
# 時刻
$now = time();
$hour = date('H', $now);
$min = date('m', $now);
$sec = date('s', $now);
$year = date('Y', $now);
$month = date('m', $now);
$day = date('d', $now);
$date = mktime($hour, $min, $sec, $month, $day, $year);
$expiration = mktime(0, 0, 0, $month, $day+1, $year);
$header = Array(
'alg' => 'RS256',
'typ' => 'JWT'
);
$header = json_encode($header);
// $header = hash("sha256", $header, true);
$claim = Array(
'iss' => $client_key,
'aud' => urlencode('https://api.researchmap.jp/oauth2/token'),
'sub' => 0,
'exp' => $expiration,
'iat' => $date
);
$claim = json_encode($claim);
// $claim = hash("sha256", $claim, true);
$signature =
$jwt = base64_encode($header) + '.' + base64_encode($claim) + '.' + base64_encode($signature);
$opts = array('https' =>
array(
'method' => 'POST',
'header' => "Content-Type: application/json; charset=utf8",
'content' => Array(
'header' => $claim,
'claim' => Array(),
),
'timeout' => 60
)
);
$context = stream_context_create($opts);
$respone = file_get_contents($url);
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Origin: *');
echo $respone;
?>