Skip to content

Commit 2604a7e

Browse files
committed
feat: add proxy-home
1 parent a4e9221 commit 2604a7e

File tree

11 files changed

+447
-6
lines changed

11 files changed

+447
-6
lines changed

setup/Setup.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ public static function setup(Event $event) {
12301230

12311231
// write proxy example files
12321232
if ($config['addProxyExample']) {
1233-
echo $colors->getColoredString("\nWrite proxy example files to www (proxy-spid.php, proxy-sample.php, proxy-login.php, error.php)... ", "white");
1233+
echo $colors->getColoredString("\nWrite proxy example files to www (proxy.php, proxy-home.php, proxy-sample.php, proxy-login.php, error.php)... ", "white");
12341234

12351235
// configuration for proxy
12361236
$vars = self::proxyVariables($config);
@@ -1239,6 +1239,10 @@ public static function setup(Event $event) {
12391239
$customized = str_replace(array_keys($vars), $vars, $template);
12401240
file_put_contents($config['wwwDir'] . "/proxy.php", $customized);
12411241

1242+
$template = file_get_contents($config['installDir'] . '/setup/sdk/proxy-home.tpl', true);
1243+
$customized = str_replace(array_keys($vars), $vars, $template);
1244+
file_put_contents($config['wwwDir'] . "/proxy-home.php", $customized);
1245+
12421246
$template = file_get_contents($config['installDir'] . '/setup/sdk/proxy-sample.tpl', true);
12431247
$customized = str_replace(array_keys($vars), $vars, $template);
12441248
file_put_contents($config['wwwDir'] . "/proxy-sample.php", $customized);
@@ -1248,11 +1252,16 @@ public static function setup(Event $event) {
12481252
file_put_contents($config['wwwDir'] . "/proxy-login.php", $customized);
12491253
if (!file_exists($config['wwwDir'] . "/error.php")) {
12501254
// add error.tpl only if not exists
1251-
$template = file_get_contents($config['installDir'] . '/setup/sdk/error.tpl', true);
1252-
$customized = str_replace(array_keys($vars), $vars, $template);
1253-
file_put_contents($config['wwwDir'] . "/error.php", $customized);
1255+
$template = file_get_contents($config['installDir'] . '/setup/sdk/error.tpl', true);
1256+
$customized = str_replace(array_keys($vars), $vars, $template);
1257+
file_put_contents($config['wwwDir'] . "/error.php", $customized);
12541258
}
12551259

1260+
$filesystem->mirror(
1261+
$config['installDir'] . "/setup/www/assets",
1262+
$config['wwwDir'] . "/assets"
1263+
);
1264+
12561265
echo $colors->getColoredString("OK", "green");
12571266
}
12581267

setup/sdk/proxy-home.tpl

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
<?php
2+
3+
require_once("{{SDKHOME}}/proxy-spid-php.php");
4+
5+
const PROXY_CONFIG_FILE = "{{SDKHOME}}/spid-php-proxy.json";
6+
const DEBUG = false;
7+
const ERR_REDIRECT = "/metadata.xml";
8+
9+
if(DEBUG) {
10+
ini_set('display_errors', 1);
11+
ini_set('display_startup_errors', 1);
12+
error_reporting(E_ALL);
13+
}
14+
15+
$proxy_config = file_exists(PROXY_CONFIG_FILE)? json_decode(file_get_contents(PROXY_CONFIG_FILE), true) : array();
16+
// always set to production to avoid test/validator button to be active while testing
17+
$production = $proxy_config['production'];
18+
$clients = $proxy_config['clients'];
19+
20+
$client_id = isset($_GET['client_id'])? $_GET['client_id'] : null;
21+
$level = (isset($_GET['level']) && $_GET['level'])? $_GET['level'] : 2;
22+
$redirect_uri = isset($_GET['redirect_uri'])? urldecode($_GET['redirect_uri']) : null;
23+
$state = (isset($_GET['state']) && $_GET['state'])? $_GET['state'] : '';
24+
$idp = isset($_GET['idp'])? $_GET['idp'] : null;
25+
26+
if($client_id==null || $client_id=='') {
27+
http_response_code(404);
28+
if(DEBUG) {
29+
echo "client_id not provided";
30+
} else {
31+
header("Location: " . ERR_REDIRECT);
32+
}
33+
die();
34+
}
35+
36+
if($level==null || $level=='') {
37+
http_response_code(404);
38+
if(DEBUG) {
39+
echo "level not provided";
40+
} else {
41+
header("Location: " . ERR_REDIRECT);
42+
}
43+
die();
44+
}
45+
46+
if($redirect_uri==null || $redirect_uri=='') {
47+
http_response_code(404);
48+
if(DEBUG) {
49+
echo "redirect_uri not provided";
50+
} else {
51+
header("Location: " . ERR_REDIRECT);
52+
}
53+
die();
54+
}
55+
56+
if(!in_array($client_id, array_keys($clients))) {
57+
http_response_code(404);
58+
if(DEBUG) {
59+
echo "client_id not found";
60+
} else {
61+
header("Location: " . ERR_REDIRECT);
62+
}
63+
die();
64+
}
65+
66+
if(!in_array($redirect_uri, $clients[$client_id]['redirect_uri'])) {
67+
http_response_code(404);
68+
if(DEBUG) {
69+
echo "redirect_uri not found";
70+
} else {
71+
header("Location: " . ERR_REDIRECT);
72+
}
73+
die();
74+
}
75+
76+
77+
$service = "service";
78+
if($idp=="CIE" || $idp=="CIE TEST") $service = "cie";
79+
$spidsdk = new PROXY_SPID_PHP($client_id, $redirect_uri, $state, $production, $service);
80+
81+
//$spidsdk->setPurpose("P");
82+
83+
$organization_name = isset($clients[$client_id]['description'])? $clients[$client_id]['description'] : '';
84+
85+
if(!$spidsdk->isAuthenticated()) {
86+
if($idp==null || $idp=='') {
87+
88+
?>
89+
<!DOCTYPE html>
90+
<html lang="it">
91+
<head>
92+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
93+
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
94+
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" />
95+
<link href="/assets/css/style.css" rel="stylesheet" />
96+
<link href="/assets/css/custom.css?v=2.1" rel="stylesheet" />
97+
<link href="/assets/css/eidas-sp-access-button.min.css" rel="stylesheet" />
98+
<link rel="preconnect" href="https://fonts.googleapis.com">
99+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
100+
<link href="https://fonts.googleapis.com/css2?family=Titillium+Web:wght@200;300;400;600;700;900&display=swap" rel="stylesheet">
101+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
102+
<?php $spidsdk->insertSPIDButtonCSS(); ?>
103+
</head>
104+
<body>
105+
<div id="root">
106+
<header aria-label="Intestazione">
107+
<div class="bg-transparent my-header" id="page-header">
108+
<div class="row align-items-sm-center">
109+
<div class="col-auto pr-0 pr-md-2">
110+
<img src="<?php echo $proxy_config['clients'][$client_id]['logo']; ?>" alt="Logo" class="logo my-2">
111+
</div>
112+
<div class="col">
113+
<h1>
114+
<?php echo $proxy_config['clients'][$client_id]['name']; ?>
115+
</h1>
116+
117+
</div>
118+
</div>
119+
</div>
120+
</header>
121+
<div id="login" class="container-fluid d-flex flex-column justify-content-between py-3 py-md-4">
122+
<div id="loginPage" class="d-flex flex-column justify-content-between">
123+
<main id="main" class="mb-5">
124+
<h1 class="align-center"><?php echo $organization_name; ?></h1>
125+
<div id="login-form" class="login-form-lg shadow mx-auto mt-3">
126+
<h2 class="h3">Accedi con identità digitale</h2>
127+
<ul class="nav nav-tabs flex-sm-row flex-sm-nowrap" role="tablist">
128+
<li class="nav-item text-sm-center" role="presentation">
129+
<a href="#tab-spid" class="nav-link h-100 px-4 active" data-bs-toggle="tab" aria-controls="tab-spid" role="tab">
130+
<i class="fas fa-user-circle mr-2"></i>SPID
131+
</a>
132+
</li>
133+
<li class="nav-item text-sm-center" role="presentation">
134+
<a href="#tab-cie" class="nav-link h-100 px-4" data-bs-toggle="tab" aria-controls="tab-cie" role="tab">
135+
<i class="fas fa-address-card mr-2"></i>CIE
136+
</a>
137+
</li>
138+
</ul>
139+
<div class="tab-content">
140+
<div id="tab-spid" class="tab-pane fade active show" role="tabpanel" aria-labelledby="tab-spid">
141+
<h3 class="sr-only">Accedi con identità digitale credenziali SPID</h3>
142+
<p>SPID, il&nbsp;<strong>Sistema Pubblico di Identità Digitale</strong>&nbsp;è il sistema di accesso che consente di utilizzare, con un'identità digitale unica, i servizi online della Pubblica Amministrazione e dei privati accreditati. Se sei già in possesso di un'identità digitale, accedi con le credenziali del tuo gestore. Se non hai ancora un'identità digitale, richiedila ad uno dei gestori.</p>
143+
144+
<div class="row align-items-center mt-3">
145+
<div class="col-12 col-md-6">
146+
<ul class="list-link px-1">
147+
<li class="mb-1">
148+
<a href="https://www.spid.gov.it/" target="_blank" rel="noopener noreferrer">
149+
<span class="sr-only">Apre una nuova finestra</span>Maggiori informazioni su SPID</a>
150+
</li>
151+
<li class="mb-1">
152+
<a href="https://www.spid.gov.it/richiedi-spid" target="_blank" rel="noopener noreferrer">
153+
<span class="sr-only">Apre una nuova finestra</span>Non hai SPID?</a>
154+
</li>
155+
<li class="mb-1">
156+
<a href="https://www.spid.gov.it/serve-aiuto" target="_blank" rel="noopener noreferrer">
157+
<span class="sr-only">Apre una nuova finestra</span>Serve aiuto?</a>
158+
</li>
159+
</ul>
160+
</div>
161+
<div class="col-12 col-md-6 text-center">
162+
<?php $spidsdk->insertSPIDButton("M"); ?>
163+
</div>
164+
</div>
165+
166+
<div class="row align-items-center mt-3">
167+
<img id="spid-agid" class="img-fluid mx-auto" src="/assets/img/spid-agid-logo-lb.png" alt="Logo SPID - AGID - Agenzia per l'Italia Digitale">
168+
</div>
169+
</div>
170+
171+
<div id="tab-cie" class="tab-pane fade" role="tabpanel" aria-labelledby="tab-cie">
172+
<h3 class="sr-only">Accedi con identità digitale CIE</h3>
173+
<p>
174+
La&nbsp;<strong>Carta di Identità Elettronica (CIE)</strong>&nbsp;è il documento personale che attesta l'identità del cittadino.&nbsp;Dotata di microprocessore, oltre a comprovare l'identità personale, permette l'accesso ai servizi digitali della Pubblica Amministrazione.
175+
</p>
176+
<!--p>
177+
<strong>L'autenticazione con CIE è attualmente in manutenzione.</strong>
178+
</p-->
179+
<div class="row align-items-center">
180+
<div class="col-12 col-md-6">
181+
<a class="my-3" href="https://www.cartaidentita.interno.gov.it/" target="_blank" rel="noopener noreferrer">
182+
<span class="sr-only">Apre una nuova finestra</span>Maggiori informazioni
183+
</a>
184+
</div>
185+
<div class="col-12 col-md-6 text-center">
186+
<a id="btn-accedi" type="submit" class="btn p-0 border-0 my-3"
187+
href="/proxy-spid.php?action=login&client_id=<?php echo $client_id; ?>&redirect_uri=<?php echo $redirect_uri; ?>&idp=CIE&state=<?php echo $state; ?>">
188+
<img class="img-fluid" src="/assets/img/button_cie.png" alt="">
189+
<span class="sr-only">Accedi con identità digitale CIE</span>
190+
</a>
191+
</div>
192+
</div>
193+
<img id="ministero-interno" class="img-fluid mx-auto" src="/assets/img/logo_mi.png" alt="Logo del Ministero dell’Interno">
194+
</div>
195+
196+
</div>
197+
</div>
198+
</main>
199+
</div>
200+
</div>
201+
<footer id="page-footer">
202+
<div class="container-fluid pb-3">
203+
<hr aria-hidden="true" />
204+
<ul class="list-inline mb-0 w-100">
205+
<li class="list-inline-item">
206+
<a href="#">Privacy</a>
207+
</li>
208+
<li class="list-inline-item">
209+
<a href="#">Note legali</a>
210+
</li>
211+
</ul>
212+
</div>
213+
</footer>
214+
</div>
215+
216+
<?php $spidsdk->insertSPIDButtonJS(); ?>
217+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"></script>
218+
</body>
219+
</html>
220+
221+
<?php
222+
} else {
223+
/***
224+
* questo branch non viene raggiunto perchè utilizzando
225+
* $spidsdk->insertSPIDButton per simplicità
226+
* il login viene effettuato da proxy-spid.php
227+
* con i valori di spid_level e atcs_index predefiniti
228+
* in spid-php-proxy.json
229+
* Quindi ogni applicativo (compreso OIDC Plugin)
230+
* non può gestirli a runtime
231+
**/
232+
233+
if($spidsdk->isIdPAvailable($idp)) {
234+
$spidsdk->login($idp, $level, "", 0);
235+
} else {
236+
if(DEBUG) {
237+
echo "idp not valid";
238+
} else {
239+
header("Location: " . ERR_REDIRECT);
240+
}
241+
}
242+
243+
// set AttributeConsumingServiceIndex 2
244+
//$spidsdk->login($idp, 2, "", 2);
245+
}
246+
247+
} else {
248+
$idp = $spidsdk->getIdPKey();
249+
$proxy_url = "/proxy-spid.php?action=login&client_id=".$client_id.
250+
"&redirect_uri=".$redirect_uri.
251+
"&state=".$state.
252+
"&idp=".$idp;
253+
254+
header("Location: " . $proxy_url);
255+
}
256+
?>

setup/sdk/proxy.tpl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
const DEFAULT_EIDAS_ATCS_INDEX = 100;
3434
const DEFAULT_SECRET = "";
3535
const DEFAULT_TOKEN_EXPIRATION_TIME = 1200;
36+
const PROXY_HOME = "/proxy-home.php";
3637
const DEBUG = false;
3738

3839
$proxy_config = file_exists(PROXY_CONFIG_FILE)? json_decode(file_get_contents(PROXY_CONFIG_FILE), true) : array();
@@ -45,6 +46,13 @@
4546
$state = $_GET['state'];
4647
$idp = $_GET['idp'];
4748

49+
$spidcie_level = $clients[$client_id]['level'];
50+
if($spidcie_level===null || !in_array($spidcie_level, [1,2,3])) $spidcie_level = $isCIE? DEFAULT_CIE_LEVEL : DEFAULT_SPID_LEVEL;
51+
52+
$atcs_index = $clients[$client_id]['atcs_index'];
53+
if($atcs_index===null || !is_numeric($atcs_index)) $atcs_index = DEFAULT_ATCS_INDEX;
54+
if($idp=="EIDAS" || $idp=="EIDAS QA") $atcs_index = DEFAULT_EIDAS_ATCS_INDEX;
55+
4856
switch($action) {
4957

5058
case "login":
@@ -62,8 +70,16 @@
6270
$spidsdk = new SPID_PHP($production, $service);
6371

6472
if(!$spidsdk->isIdPAvailable($idp)) {
65-
http_response_code(404);
66-
if(DEBUG) echo "idp not found";
73+
if(PROXY_HOME) {
74+
header('Location: ' . PROXY_HOME .
75+
'?client_id=' . $client_id .
76+
'&level=' . $spidcie_level .
77+
'&redirect_uri=' . $redirect_uri);
78+
} else {
79+
http_response_code(404);
80+
if(DEBUG) echo "idp not found";
81+
}
82+
6783
die();
6884
}
6985

@@ -106,12 +122,14 @@
106122
die();
107123

108124
} else {
125+
/*
109126
$spidcie_level = $clients[$client_id]['level'];
110127
$atcs_index = $clients[$client_id]['atcs_index'];
111128
if($spidcie_level===null || !in_array($spidcie_level, [1,2,3])) $spidcie_level = $isCIE? DEFAULT_CIE_LEVEL : DEFAULT_SPID_LEVEL;
112129
if($atcs_index===null || !is_numeric($atcs_index)) $atcs_index = DEFAULT_ATCS_INDEX;
113130
114131
if($idp=="EIDAS" || $idp=="EIDAS QA") $atcs_index = DEFAULT_EIDAS_ATCS_INDEX;
132+
*/
115133

116134
$returnTo = $_SERVER['SCRIPT_URI'].'?action=login&idp='.$idp.'&client_id='.$client_id.'&redirect_uri='.$redirect_uri.'&state='.$state;
117135
setcookie('SPIDPHP_PROXYRETURNTO', $returnTo, time()+60*5, '/');

0 commit comments

Comments
 (0)