Skip to content

Commit c42edce

Browse files
authored
Introduce installation script (#214)
* Introduce installation script to support automatic deployments * Update readme --------- Co-authored-by: Marko Ivančić <[email protected]>
1 parent fe6f648 commit c42edce

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ The module comes with some default SQL migrations which set up needed tables in
6060
open the _Federation_ tab from your _SimpleSAMLphp_ installation and select the option _OpenID Connect Installation_
6161
inside the _Tools_ section. Once there, all you need to do is press the _Install_ button and the schema will be created.
6262

63+
Alternatively, in case of automatic / scripted deployments, you can run the 'install.php' script from the command line:
64+
65+
php modules/oidc/bin/install.php
66+
6367
### Relying Party (RP) Administration
6468

6569
The module lets you manage (create, read, update and delete) approved RPs from the module user interface itself.

bin/install.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
/**
7+
* Script which can be run to do the module installation which includes running database migrations.
8+
*/
9+
10+
use SimpleSAML\Database;
11+
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
12+
13+
// This is the base directory of the SimpleSAMLphp installation
14+
$baseDir = dirname(__FILE__, 4);
15+
16+
// Add library autoloader and configuration
17+
require_once $baseDir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . '_autoload.php';
18+
19+
echo 'Starting with module installation.' . PHP_EOL;
20+
21+
try {
22+
$database = Database::getInstance();
23+
$databaseMigration = new DatabaseMigration($database);
24+
25+
if ($databaseMigration->isUpdated()) {
26+
echo 'Database is up to date, skipping.' . PHP_EOL;
27+
return 0;
28+
}
29+
30+
echo 'Running database migrations.' . PHP_EOL;
31+
32+
$databaseMigration->migrate();
33+
34+
echo 'Done running migrations.';
35+
return 0;
36+
} catch (Throwable $exception) {
37+
echo 'There was an error while trying run database migrations: ' . $exception->getMessage();
38+
return 1;
39+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
},
5151
"sort-packages": true,
5252
"allow-plugins": {
53-
"simplesamlphp/composer-module-installer": true
53+
"simplesamlphp/composer-module-installer": true,
54+
"dealerdirect/phpcodesniffer-composer-installer": true
5455
},
5556
"cache-dir": "build/composer"
5657
},

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<UnusedClass errorLevel="suppress" />
4545
<PossiblyUnusedMethod errorLevel="suppress" />
4646
<PossiblyUnusedReturnValue errorLevel="suppress" />
47+
48+
<!-- Ignore RiskyTruthyFalsyComparison -->
49+
<RiskyTruthyFalsyComparison errorLevel="suppress" />
4750
</issueHandlers>
4851
</psalm>
4952

src/Forms/ClientForm.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
namespace SimpleSAML\Module\oidc\Forms;
1818

1919
use Exception;
20+
use Nette\Forms\Container;
2021
use Nette\Forms\Form;
2122
use SimpleSAML\Auth\Source;
2223
use SimpleSAML\Module\oidc\ModuleConfig;
2324
use SimpleSAML\Module\oidc\Forms\Controls\CsrfProtection;
2425
use Traversable;
2526

27+
/**
28+
* @psalm-suppress PropertyNotSetInConstructor Raised for $httpRequest which is marked as internal, so won't handle.
29+
*/
2630
class ClientForm extends Form
2731
{
2832
protected const TYPE_ARRAY = 'array';
@@ -123,7 +127,7 @@ protected function validateByMatchingRegex(
123127
}
124128
}
125129

126-
public function getValues($returnType = null, ?array $controls = null): array
130+
public function getValues(string|object|bool|null $returnType = null, ?array $controls = null): array
127131
{
128132
/** @var array $values */
129133
$values = parent::getValues(self::TYPE_ARRAY);
@@ -157,7 +161,7 @@ public function getValues($returnType = null, ?array $controls = null): array
157161
/**
158162
* @throws Exception
159163
*/
160-
public function setDefaults($data, bool $erase = false): ClientForm
164+
public function setDefaults(object|array $data, bool $erase = false): static
161165
{
162166
if (! is_array($data)) {
163167
if ($data instanceof Traversable) {
@@ -187,7 +191,9 @@ public function setDefaults($data, bool $erase = false): ClientForm
187191
$scopes = is_array($data['scopes']) ? $data['scopes'] : [];
188192
$data['scopes'] = array_intersect($scopes, array_keys($this->getScopes()));
189193

190-
return parent::setDefaults($data, $erase);
194+
parent::setDefaults($data, $erase);
195+
196+
return $this;
191197
}
192198

193199
/**
@@ -203,7 +209,7 @@ protected function buildForm(): void
203209
$this->onValidate[] = $this->validateBackChannelLogoutUri(...);
204210

205211
$this->setMethod('POST');
206-
$this->addComponent(new CsrfProtection('{oidc:client:csrf_error}'), Form::PROTECTOR_ID);
212+
$this->addComponent(new CsrfProtection('{oidc:client:csrf_error}'), Form::ProtectorId);
207213

208214
$this->addText('name', '{oidc:client:name}')
209215
->setMaxLength(255)

src/Forms/Controls/CsrfProtection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Nette\InvalidStateException;
2222
use Nette\Utils\Random;
2323
use SimpleSAML\Session;
24+
use Stringable;
2425

2526
class CsrfProtection extends BaseCsrfProtection
2627
{
@@ -32,7 +33,7 @@ class CsrfProtection extends BaseCsrfProtection
3233
/**
3334
* @throws Exception
3435
*/
35-
public function __construct(object|string $errorMessage)
36+
public function __construct(string|Stringable|null $errorMessage)
3637
{
3738
// Instead of calling CsrfProtection parent class constructor, go to it's parent (HiddenField), and call
3839
// its constructor. This is to avoid setting a Nette session in CsrfProtection parent, and use the SSP one.

src/Utils/ClaimTranslatorExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function addClaimSet(ClaimSetEntityInterface $claimSet): self
197197
{
198198
$scope = $claimSet->getScope();
199199

200-
if (in_array($scope, $this->protectedClaims) && !empty($this->claimSets[$scope])) {
200+
if (in_array($scope, $this->protectedClaims) && isset($this->claimSets[$scope])) {
201201
throw OidcServerException::serverError(
202202
sprintf("%s is a protected scope and is pre-defined by the OpenID Connect specification.", $scope)
203203
);

0 commit comments

Comments
 (0)