forked from italia/spid-php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload_idp_metadata.php
More file actions
executable file
·56 lines (52 loc) · 1.69 KB
/
Copy pathdownload_idp_metadata.php
File metadata and controls
executable file
·56 lines (52 loc) · 1.69 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
#!/usr/bin/php
<?php
// downloads the metadata for all current production IdPs from the registry
// and stores them all in the specified directory
//
// prerequisites:
// sudo apt install php-curl
//
// usage:
// ./bin/download_idp_metadata.php /tmp/idp_metadata
//
// Copyright (c) 2018, Paolo Greppi <paolo.greppi@simevo.com>
// License: BSD 3-Clause
if (count($argv) <= 1) {
echo "Usage: download_idp_metadata.php destination_dir_without_trailing_slash\n";
exit(-1);
}
$dir = $argv[1];
$idp_list_url = 'https://registry.spid.gov.it/assets/data/idp.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $idp_list_url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
echo "Contacting $idp_list_url" . PHP_EOL;
$json = curl_exec($ch);
curl_close($ch);
$idps = json_decode($json);
foreach ($idps->data as $idp) {
$metadata_url = $idp->metadata_url;
$ipa_entity_code = $idp->ipa_entity_code;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $metadata_url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
echo "Contacting $metadata_url" . PHP_EOL;
$xml = curl_exec($ch);
// $info = curl_getinfo($ch);
// echo ('curl info = ');
// var_dump($info);
if ($xml === false) {
echo 'Operation failed with error: ' . curl_error($ch) . PHP_EOL;
} else {
// operation completed successfully
$file = "$dir/$ipa_entity_code.xml";
file_put_contents($file, $xml);
}
curl_close($ch);
}