'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);