-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_session.php
88 lines (77 loc) · 2.36 KB
/
start_session.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require_once 'config.php';
date_default_timezone_set('UTC');
$protocol = explode(':', IRMA_SERVER_URL, 2)[0];
$sprequests = [
'18plus' => [
'@context' => 'https://irma.app/ld/request/disclosure/v2',
'disclose' => [
[
['pbdf.pbdf.ageLimits.over18'],
['pbdf.nijmegen.ageLimits.over18'],
['pbdf.gemeente.personalData.over18'],
['pbdf.pilot-amsterdam.idcard.over18'],
['pbdf.pilot-amsterdam.passport.over18'],
],
],
],
'16plus' => [
'@context' => 'https://irma.app/ld/request/disclosure/v2',
'disclose' => [
[
['pbdf.pbdf.ageLimits.over16'],
['pbdf.nijmegen.ageLimits.over16'],
['pbdf.gemeente.personalData.over16'],
['pbdf.pilot-amsterdam.idcard.over16'],
['pbdf.pilot-amsterdam.passport.over16'],
],
],
],
'12plus' => [
'@context' => 'https://irma.app/ld/request/disclosure/v2',
'disclose' => [
[
['pbdf.pbdf.ageLimits.over12'],
['pbdf.nijmegen.ageLimits.over12'],
['pbdf.gemeente.personalData.over12'],
['pbdf.pilot-amsterdam.idcard.over12'],
['pbdf.pilot-amsterdam.passport.over12'],
],
],
],
];
function start_session($type) {
global $sprequests, $protocol;
if (array_key_exists($type, $sprequests))
$sessionrequest = $sprequests[$type];
else
stop();
$jsonsr = json_encode($sessionrequest);
$api_call = array(
$protocol => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n"
. "Content-Length: " . strlen($jsonsr) . "\r\n"
. (!empty(API_TOKEN) ? "Authorization: " . API_TOKEN . "\r\n" : ""),
'content' => $jsonsr
)
);
$resp = file_get_contents(IRMA_SERVER_URL . '/session', false, stream_context_create($api_call));
if (! $resp) {
error();
}
return $resp;
}
function error() {
http_response_code(500);
echo 'Internal server error';
exit();
}
function stop() {
http_response_code(400);
echo 'Invalid request';
exit();
}
if (!isset($_GET['type']))
stop();
echo start_session($_GET['type']);