Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
67 righe
2.3 KiB
67 righe
2.3 KiB
<?php |
|
|
|
//define('SERVER_NAME', 'autenticazione.lavoripubblici.sicilia.it'); |
|
define('SERVER_NAME', 'auth.mwg.it'); |
|
define('CLIENT_ID', 'https://' . SERVER_NAME); |
|
define('CLIENT_NAME', 'Autenticazione Lavori Pubblici Sicilia'); |
|
define('REDIRECT_URIS', ['https://' . SERVER_NAME . '/spid/callback/']); |
|
define('JWKS_URI', 'https://' . SERVER_NAME . '/openidc/jwks.json'); |
|
|
|
$distinguished_names = [ |
|
'countryName' => 'IT', |
|
'stateOrProvinceName' => 'Sicilia', |
|
"organizationName" => 'Regione Siciliana', |
|
"organizationalUnitName" => 'Assessorato Infrastrutture, Trasporti e Mobilità', |
|
"commonName" => SERVER_NAME, |
|
"emailAddress" => 'info@lavoripubblici.sicilia.it', |
|
]; |
|
|
|
define('OPENIDC_PATH', '/var/www/html/openidc'); |
|
define('PRIVATE_KEY', 'private.pem'); |
|
define('PUBLIC_KEY', 'public.pem'); |
|
|
|
if (file_exists(PRIVATE_KEY)) { |
|
$private = openssl_pkey_get_private(file_get_contents(PRIVATE_KEY)); |
|
} else { |
|
$private = openssl_pkey_new([ |
|
'private_key_bits' => 4096, |
|
'private_key_type' => OPENSSL_KEYTYPE_RSA, |
|
]); |
|
openssl_pkey_export_to_file($private, 'private.pem'); |
|
} |
|
$details = openssl_pkey_get_details($private); |
|
file_put_contents(PUBLIC_KEY, $details['key']); |
|
// $csr = openssl_csr_new($distinguished_names, $private); |
|
// $x509 = openssl_csr_sign($csr, null, $private, 3650, ['digest_alg' => 'sha512']); |
|
// openssl_pkcs12_export_to_file($x509, 'privatekeys.pfx', $private, 'm4n1f'); |
|
$jwks = [ |
|
'keys' => [ |
|
[ |
|
'kty' => 'RSA', |
|
'alg' => 'RS256', |
|
'use' => 'sig', |
|
'kid' => 'auth', |
|
'n' => base64_encode($details['rsa']['n']), |
|
'e' => base64_encode($details['rsa']['e']), |
|
], |
|
], |
|
]; |
|
if (!is_dir(OPENIDC_PATH)) { |
|
mkdir(OPENIDC_PATH, 0777, true); |
|
} |
|
file_put_contents(OPENIDC_PATH . '/jwks.json', json_encode($jwks, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
|
$metadata = json_encode([ |
|
'client_id' => CLIENT_ID, |
|
'client_name' => CLIENT_NAME, |
|
'grant_types' => [ |
|
'authorization_code', |
|
'refresh_token', |
|
], |
|
'jwks_uri' => JWKS_URI, |
|
'jwks' => $jwks, |
|
'redirect_uris' => REDIRECT_URIS, |
|
'response_types' => [ |
|
'code', |
|
], |
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
file_put_contents(OPENIDC_PATH . '/metadata.json', $metadata);
|
|
|