-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from italia/feature/issue-65-certs
fix #65
- Loading branch information
Showing
9 changed files
with
218 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,13 @@ $settings = array( | |
], | ||
'sp_org_name' => 'your organization full name', | ||
'sp_org_display_name' => 'your organization display name', | ||
'sp_key_cert_values' => [ | ||
'countryName' => 'Your Country', | ||
'stateOrProvinceName' => 'Your Province or State', | ||
'localityName' => 'Locality', | ||
'commonName' => 'Name', | ||
'emailAddress' => '[email protected]', | ||
] | ||
'idp_metadata_folder' => '/path/to/idp_metadata/', | ||
'sp_attributeconsumingservice' => [ | ||
// order is important ! the 0-base index in this array will be used as ID in the calls | ||
|
@@ -196,10 +203,12 @@ The method will redirect to the IdP Single Logout page, or return false if you a | |
|getSPMetadata() : string|returns the SP metadata as a string| | ||
|login(string $idpFilename, int $assertID, int $attrID, $level = 1, string $redirectTo = null, $shouldRedirect = true)|login with REDIRECT binding. Use `$idpFilename` to select in IdP for login by indicating the name (without extension) of an XML file in your `idp_metadata_folder`. `$assertID` and `$attrID` indicate respectively the array index of `sp_assertionconsumerservice` and `sp_attributeconsumingservice` provided in settings. Optional parameters: `$level` for SPID authentication level (1, 2 or 3), `$redirectTo` to indicate an url to redirect to after login, `$shouldRedirect` to indicate if the login function should automatically redirect to the IdP or should return the login url as a string| | ||
|loginPost(string $idpName, int $ass, int $attr, $level = 1, string $redirectTo = null, $shouldRedirect = true)|like login, but uses POST binding| | ||
|public function logout(int $slo, string $redirectTo = null, $shouldRedirect = true)|logout with REDIRECT binding. `$slo` indicates the array index of the `sp_singlelogoutservice` provided in settings. Optional parameters: `$redirectTo` to indicate an url to redirect to after login, `$shouldRedirect` to indicate if the login function should automatically redirect to the IdP or should return the login url as a string| | ||
|logout(int $slo, string $redirectTo = null, $shouldRedirect = true)|logout with REDIRECT binding. `$slo` indicates the array index of the `sp_singlelogoutservice` provided in settings. Optional parameters: `$redirectTo` to indicate an url to redirect to after login, `$shouldRedirect` to indicate if the login function should automatically redirect to the IdP or should return the login url as a string| | ||
|logoutPost(int $slo, string $redirectTo = null, $shouldRedirect = true)|like logout, but uses POST binding| | ||
|isAuthenticated() : bool|checks if the user is authenticated. This method **MUST** be caled after login and logout to finalise the operation.| | ||
|getAttributes() : array|If you requested attributes with an attribute consuming service during login, this method will return them in array format| | ||
|isConfigured() : bool|Returns true if the SP certificates are found where the settings says they are, and they are valid (i.e. the library has been configured correctly)| | ||
|configure(string $countryName, string $stateName, string $localityName, string $commonName, string $emailAddress)|Generates the SP key and certificate (validity = 10 years) where the settings says they should be; this function should be used with care because it requires write access to the filessystem, and invalidates the metadata| | ||
|
||
### Example | ||
|
||
|
@@ -339,7 +348,6 @@ cd vendor/italia/spid-php-lib | |
Install prerequisites with composer, generate key and certificate for the SP and download the metadata for all current production IdPs with: | ||
```sh | ||
composer install | ||
make -C example/ | ||
bin/download_idp_metadata.php example/idp_metadata | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,13 @@ | |
], | ||
'sp_org_name' => 'test', | ||
'sp_org_display_name' => 'Test', | ||
'sp_key_cert_values' => [ | ||
'countryName' => 'IT', | ||
'stateOrProvinceName' => 'Milan', | ||
'localityName' => 'Milan', | ||
'commonName' => 'Name', | ||
'emailAddress' => '[email protected]', | ||
], | ||
'idp_metadata_folder' => './idp_metadata/', | ||
'sp_attributeconsumingservice' => [ | ||
["name", "familyName", "fiscalNumber", "email"], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,24 @@ interface SAMLInterface | |
// ], | ||
// 'sp_org_name' => 'your organization full name', | ||
// 'sp_org_display_name' => 'your organization display name', | ||
// 'sp_key_cert_values' => [ | ||
// 'countryName' => 'CN', | ||
// 'stateOrProvinceName' => 'State', | ||
// 'localityName' => 'Locality', | ||
// 'commonName' => 'Name', | ||
// 'emailAddress' => '[email protected]', | ||
// ], | ||
// 'idp_metadata_folder' => '/path/to/idp_metadata/', | ||
// 'sp_attributeconsumingservice' => [ | ||
// // order is important ! the 0-base index in this array will be used as ID in the calls | ||
// ["fiscalNumber"], | ||
// ["name", "familyName", "fiscalNumber", "email", "spidCode"], | ||
// ... | ||
// ]; | ||
public function __construct(array $settings); | ||
// | ||
// $autoconfigure: boolean value, determines if SP key and cert files should be autogenerated base on values provided in settings | ||
// If set to false this step will be skipped | ||
public function __construct(array $settings, $autoconfigure = true); | ||
|
||
// loads an Idp object by parsing the provided XML at $filename | ||
// $filename: file name of the IdP to be loaded. Only the file, without the path, needs to be provided. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,13 @@ final class SpTest extends PHPUnit\Framework\TestCase | |
], | ||
'sp_org_name' => 'test_simevo', | ||
'sp_org_display_name' => 'Test Simevo', | ||
'sp_key_cert_values' => [ | ||
'countryName' => 'IT', | ||
'stateOrProvinceName' => 'Milan', | ||
'localityName' => 'Milan', | ||
'commonName' => 'Name', | ||
'emailAddress' => '[email protected]', | ||
], | ||
'idp_metadata_folder' => './example/idp_metadata/', | ||
'sp_attributeconsumingservice' => [ | ||
["name", "familyName", "fiscalNumber", "email"], | ||
|
@@ -29,6 +36,31 @@ public function testCanBeCreatedFromValidSettings() | |
Italia\Spid\Sp::class, | ||
new Italia\Spid\Sp(SpTest::$settings) | ||
); | ||
$this->assertTrue(is_readable(self::$settings['sp_key_file'])); | ||
$this->assertTrue(is_readable(self::$settings['sp_cert_file'])); | ||
} | ||
|
||
public function testCanBeCreatedWithoutAutoconfigure() | ||
{ | ||
$settings = SpTest::$settings; | ||
$settings['sp_key_file'] = './wrong/location/sp.key'; | ||
$settings['sp_cert_file'] = './wrong/location/sp.crt'; | ||
$this->assertInstanceOf( | ||
Italia\Spid\Sp::class, | ||
new Italia\Spid\Sp(SpTest::$settings, null, false) | ||
); | ||
$this->assertFalse(is_readable($settings['sp_key_file'])); | ||
$this->assertFalse(is_readable($settings['sp_cert_file'])); | ||
} | ||
|
||
public function testCannotCreateNoKeyCert() | ||
{ | ||
$this->assertInstanceOf( | ||
Italia\Spid\Sp::class, | ||
new Italia\Spid\Sp(SpTest::$settings, null, false) | ||
); | ||
$this->assertTrue(is_readable(self::$settings['sp_key_file'])); | ||
$this->assertTrue(is_readable(self::$settings['sp_cert_file'])); | ||
} | ||
|
||
private function validateXml($xmlString, $schemaFile, $valid = true) | ||
|