v2.php 1.43 KB
<?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;
?>