-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_session_request.php
55 lines (47 loc) · 1.45 KB
/
get_session_request.php
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
require_once 'vendor/autoload.php';
require_once 'config.php';
use \Firebase\JWT\JWT;
use \Firebase\JWT\Key;
function get_session_request($contents)
{
if (JWT_ENABLED) {
$jwt_pk = file_get_contents(IRMA_SERVER_PUBLICKEY);
try {
$decoded = JWT::decode($contents, new Key($jwt_pk, 'RS256'));
} catch (Exception $e) {
error_log("JWT could not be parsed: " . $e);
header("HTTP/1.0 403 Forbidden");
exit;
};
} else {
$decoded = json_decode($contents, false);
if (is_null($decoded)) {
error_log("JSON could not be parsed.");
header("HTTP/1.0 403 Forbidden");
exit;
}
}
$fullname = $decoded->disclosed[0][0]->rawvalue;
if (!$fullname) {
$fullname = "John Doe";
}
$randomnum = rand(1, 9);
for ($i = 0; $i < 10; $i++)
$randomnum .= rand(0, 9);
$sessionrequest = [
'@context' => 'https://irma.app/ld/request/issuance/v2',
'credentials' => [[
'credential' => IRMATUBE_CREDENTIAL,
'validity' => strtotime('+6 months'),
'attributes' => [
'fullname' => $fullname,
'type' => 'premium',
'id' => $randomnum
]
]]
];
return json_encode($sessionrequest);
}
header('Access-Control-Allow-Origin: ' . BASE_URL);
echo get_session_request(file_get_contents('php://input'));