diff --git a/README.md b/README.md index a3daa35..982ac05 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,14 @@ php artisan migrate Once you publish `saml2.php` to `app/config`, you need to configure your SP. Most of options are inherited from [OneLogin Toolkit](https://github.com/onelogin/php-saml), so you can check documentation there. +#### Service Provider Certificate Creation (SP certificate) + +``` +php artisan saml2:cert +``` + +Once you create the certificates, configure your SP `SAML2_SP_CERT_x509` and `SAML2_SP_CERT_PRIVATEKEY`. + #### Identity Providers (IdPs) To distinguish between identity providers there is an entity called Tenant that represent each IdP. diff --git a/src/Commands/CreateCertificate.php b/src/Commands/CreateCertificate.php new file mode 100644 index 0000000..7a870cf --- /dev/null +++ b/src/Commands/CreateCertificate.php @@ -0,0 +1,67 @@ +option('days'); + $keyname = $this->option('keyname'); + $certname = $this->option('certname'); + + // Create storage/samlidp directory + if (!file_exists($storagePath)) { + mkdir($storagePath, 0755, true); + } + + $key = sprintf('%s/%s', $storagePath, $keyname); + $cert = sprintf('%s/%s', $storagePath, $certname); + $question = 'The name chosen for the PEM files already exist. Would you like to overwrite existing PEM files?'; + if ((!file_exists($key) && !file_exists($cert)) || $this->confirm($question)) { + $command = 'openssl req -x509 -sha256 -nodes -days %s -newkey rsa:2048 -keyout %s -out %s'; + exec(sprintf($command, $days, $key, $cert)); + $this->info("The certificate was successfully created."); + } + } +} \ No newline at end of file diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 72a414f..b33f0ae 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -63,6 +63,7 @@ protected function bootPublishes() protected function bootCommands() { $this->commands([ + \Slides\Saml2\Commands\CreateCertificate::class, \Slides\Saml2\Commands\CreateTenant::class, \Slides\Saml2\Commands\UpdateTenant::class, \Slides\Saml2\Commands\DeleteTenant::class,