Skip to content

Commit 444968f

Browse files
authored
Reset client auth source if not valid (#280)
1 parent 9989c82 commit 444968f

File tree

9 files changed

+536
-22
lines changed

9 files changed

+536
-22
lines changed

src/Bridges/SspBridge.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SimpleSAML\Module\oidc\Bridges;
66

7+
use SimpleSAML\Module\oidc\Bridges\SspBridge\Auth;
78
use SimpleSAML\Module\oidc\Bridges\SspBridge\Module;
89
use SimpleSAML\Module\oidc\Bridges\SspBridge\Utils;
910

@@ -13,6 +14,7 @@
1314
*/
1415
class SspBridge
1516
{
17+
protected static ?Auth $auth = null;
1618
protected static ?Utils $utils = null;
1719
protected static ?Module $module = null;
1820

@@ -25,4 +27,9 @@ public function module(): Module
2527
{
2628
return self::$module ??= new Module();
2729
}
30+
31+
public function auth(): Auth
32+
{
33+
return self::$auth ??= new Auth();
34+
}
2835
}

src/Bridges/SspBridge/Auth.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Bridges\SspBridge;
6+
7+
use SimpleSAML\Module\oidc\Bridges\SspBridge\Auth\Source;
8+
9+
class Auth
10+
{
11+
protected static ?Source $source = null;
12+
13+
public function source(): Source
14+
{
15+
return self::$source ??= new Source();
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Bridges\SspBridge\Auth;
6+
7+
class Source
8+
{
9+
public function getSources(): array
10+
{
11+
return \SimpleSAML\Auth\Source::getSources();
12+
}
13+
}

src/Forms/ClientForm.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
namespace SimpleSAML\Module\oidc\Forms;
1818

1919
use Nette\Forms\Form;
20-
use SimpleSAML\Auth\Source;
2120
use SimpleSAML\Locale\Translate;
21+
use SimpleSAML\Module\oidc\Bridges\SspBridge;
2222
use SimpleSAML\Module\oidc\Forms\Controls\CsrfProtection;
2323
use SimpleSAML\Module\oidc\ModuleConfig;
2424
use SimpleSAML\OpenID\Codebooks\ClientRegistrationTypesEnum;
@@ -58,8 +58,11 @@ class ClientForm extends Form
5858
/**
5959
* @throws \Exception
6060
*/
61-
public function __construct(private readonly ModuleConfig $moduleConfig, protected CsrfProtection $csrfProtection)
62-
{
61+
public function __construct(
62+
protected readonly ModuleConfig $moduleConfig,
63+
protected CsrfProtection $csrfProtection,
64+
protected SspBridge $sspBridge,
65+
) {
6366
parent::__construct();
6467

6568
$this->buildForm();
@@ -315,6 +318,14 @@ public function setDefaults(object|array $data, bool $erase = false): static
315318

316319
$data['jwks'] = is_array($data['jwks']) ? json_encode($data['jwks']) : null;
317320

321+
if (
322+
$data['auth_source'] !== null &&
323+
(!in_array($data['auth_source'], $this->sspBridge->auth()->source()->getSources()))
324+
) {
325+
// Possible auth source name change without prior update in clients, resetting.
326+
$data['auth_source'] = null;
327+
}
328+
318329
parent::setDefaults($data, $erase);
319330

320331
return $this;
@@ -355,10 +366,9 @@ protected function buildForm(): void
355366

356367
$this->addCheckbox('is_confidential', '{oidc:client:is_confidential}');
357368

358-
// TODO mivanci Source::getSource() move to SSP Bridge.
359369
$this->addSelect('auth_source', '{oidc:client:auth_source}:')
360370
->setHtmlAttribute('class', 'full-width')
361-
->setItems(Source::getSources(), false)
371+
->setItems($this->sspBridge->auth()->source()->getSources(), false)
362372
->setPrompt(Translate::noop('-'));
363373

364374
$scopes = $this->getScopes();

0 commit comments

Comments
 (0)