Skip to content

Commit bbbfa6f

Browse files
committed
WIP Move to SSP UI
1 parent c7d4699 commit bbbfa6f

File tree

19 files changed

+388
-57
lines changed

19 files changed

+388
-57
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PHP version requirement changes in minor releases for SimpleSAMLphp.
3434

3535
### Upgrading?
3636

37-
If you are upgrading from a previous version, checkout the [upgrade guide](UPGRADE.md).
37+
If you are upgrading from a previous version, make sure to check the [upgrade guide](UPGRADE.md).
3838

3939
## Installation
4040

@@ -107,14 +107,12 @@ SimpleSAMLphp configuration file, `config/config.php`.
107107
'oidc' => true,
108108
],
109109

110-
This is required the enable the module on the _Federation_ tab in the admin web interface, which can be used in the
111-
next two steps to finalize the installation.
110+
Once the module is enabled, the database migrations must be run.
112111

113112
### Run database migrations
114113

115114
The module comes with some default SQL migrations which set up needed tables in the configured database. To run them,
116-
open the _Federation_ tab from your _SimpleSAMLphp_ installation and select the option _OpenID Connect Installation_
117-
inside the _Tools_ section. Once there, all you need to do is press the _Install_ button and the schema will be created.
115+
go to `OIDC` > `Database Migrations`, and press the available button.
118116

119117
Alternatively, in case of automatic / scripted deployments, you can run the 'install.php' script from the command line:
120118

@@ -124,8 +122,7 @@ Alternatively, in case of automatic / scripted deployments, you can run the 'ins
124122

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

127-
Once the database schema has been created, you can open the _Federation_ tab from your _SimpleSAMLphp_ installation
128-
and select the option _OpenID Connect Client Registry_ inside the _Tools_ section.
125+
Once the database schema has been created, you can go to `OIDC` > `Client Registry`.
129126

130127
Note that clients can be marked as confidential or public. If the client is not marked as confidential (it is public),
131128
and is using Authorization Code flow, it will have to provide PKCE parameters during the flow.

UPGRADE.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ key `authproc.oidc`
7979

8080
## Low impact changes
8181

82-
Below are some internal changes that should not have impact for the OIDC OP implementors. However, if you are using
82+
In an effort to move to SimpleSAMLphp way of working with user interface (UI), the client management UI was updated
83+
to extend from the SimpleSAMLphp base template. In addition, we have also introduced some configuration overview pages
84+
where you can take a quick view of some of the configuration values for the module. OIDC related pages are now available
85+
from the main SimpleSAMLphp menu in Administration area.
86+
87+
Below are also some internal changes that should not have impact for the OIDC OP implementors. However, if you are using
8388
this module as a library or extending from it, you will probably encounter breaking changes, since a lot of code
8489
has been refactored:
8590

docs/oidc.png

25.5 KB
Loading

hooks/hook_adminmenu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function oidc_hook_adminmenu(Template &$template): void
2020

2121
$oidcMenuEntry = [
2222
ModuleConfig::MODULE_NAME => [
23-
'url' => $moduleConfig->getModuleUrl(RoutesEnum::AdminConfigProtocol->value),
23+
'url' => $moduleConfig->getModuleUrl(RoutesEnum::AdminMigrations->value),
2424
'name' => Translate::noop('OIDC'),
2525
],
2626
];

hooks/hook_federationpage.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use SimpleSAML\Locale\Translate;
1818
use SimpleSAML\Module;
19+
use SimpleSAML\Module\oidc\ModuleConfig;
1920
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
2021
use SimpleSAML\XHTML\Template;
2122

@@ -24,12 +25,17 @@
2425
*/
2526
function oidc_hook_federationpage(Template $template): void
2627
{
27-
$href = Module::getModuleURL('oidc/admin-clients/index.php');
28-
$text = Translate::noop('OpenID Connect Registry');
28+
$routes = new Module\oidc\Utils\Routes(
29+
new ModuleConfig(),
30+
new Module\oidc\Bridges\SspBridge(),
31+
);
32+
33+
$href = $routes->urlAdminClients();
34+
$text = Translate::noop('OIDC Client Registry');
2935

3036
if (! (new DatabaseMigration())->isMigrated()) {
31-
$href = Module::getModuleURL('oidc/install.php');
32-
$text = Translate::noop('OpenID Connect Installation');
37+
$href = $routes->urlAdminMigrations();
38+
$text = Translate::noop('OIDC Installation');
3339
}
3440

3541
if (!is_array($template->data['links'])) {

public/assets/css/src/default.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ table.client-table {
115115

116116
.confirm-action {}
117117

118-
form.pure-form-stacked input {
118+
form.pure-form-stacked .full-width {
119119
width: 100%;
120120
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function () {
2+
'use strict';
3+
4+
// Handle enabling and disabling input for 'allowed origins', based on client type radio input.
5+
function toggleAllowedOrigins() {
6+
if (radioOptionPublic.checked) {
7+
inputAllowedOrigin.disabled = false; // Enable the input field
8+
} else if (radioOptionConfidential.checked) {
9+
inputAllowedOrigin.disabled = true; // Disable the input field
10+
}
11+
}
12+
13+
// Get references to the radio buttons and the input field
14+
const radioOptionPublic = document.getElementById("radio-option-public");
15+
const radioOptionConfidential = document.getElementById("radio-option-confidential");
16+
const inputAllowedOrigin = document.getElementById("frm-allowed_origin");
17+
18+
radioOptionPublic.addEventListener("change", toggleAllowedOrigins);
19+
radioOptionConfidential.addEventListener("change", toggleAllowedOrigins);
20+
21+
toggleAllowedOrigins();
22+
})();

routing/routes/routes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
$routes->add(RoutesEnum::AdminClientsShow->name, RoutesEnum::AdminClientsShow->value)
4848
->controller([ClientController::class, 'show'])
4949
->methods([HttpMethodsEnum::GET->value]);
50+
$routes->add(RoutesEnum::AdminClientsEdit->name, RoutesEnum::AdminClientsEdit->value)
51+
->controller([ClientController::class, 'edit'])
52+
->methods([HttpMethodsEnum::GET->value, HttpMethodsEnum::POST->value]);
5053
$routes->add(RoutesEnum::AdminClientsResetSecret->name, RoutesEnum::AdminClientsResetSecret->value)
5154
->controller([ClientController::class, 'resetSecret'])
5255
->methods([HttpMethodsEnum::POST->value]);

src/Codebooks/RoutesEnum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum RoutesEnum: string
1919

2020
case AdminClients = 'admin/clients';
2121
case AdminClientsShow = 'admin/clients/show';
22+
case AdminClientsEdit = 'admin/clients/edit';
2223
case AdminClientsAdd = 'admin/clients/add';
2324
case AdminClientsResetSecret = 'admin/clients/reset-secret';
2425
case AdminClientsDelete = 'admin/clients/delete';

src/Controllers/Admin/ClientController.php

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function add(): Response
168168

169169
$owner = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();
170170

171-
$client = $this->buildClientFromFormData(
171+
$client = $this->buildClientEntityFromFormData(
172172
$form,
173173
$this->sspBridge->utils()->random()->generateID(),
174174
$this->sspBridge->utils()->random()->generateID(),
@@ -179,6 +179,8 @@ public function add(): Response
179179
$owner,
180180
);
181181

182+
// TODO mivanci Check if the entity identifier already exists.
183+
182184
$this->clientRepository->add($client);
183185

184186
// Also persist allowed origins for this client.
@@ -209,11 +211,75 @@ public function add(): Response
209211
);
210212
}
211213

214+
/**
215+
* @throws \SimpleSAML\Error\ConfigurationError
216+
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
217+
* @throws \SimpleSAML\Error\Exception
218+
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
219+
* @throws \JsonException
220+
*/
221+
public function edit(Request $request): Response
222+
{
223+
$originalClient = $this->getClientFromRequest($request);
224+
$clientAllowedOrigins = $this->allowedOriginRepository->get($originalClient->getIdentifier());
225+
$form = $this->formFactory->build(ClientForm::class);
226+
227+
$clientData = $originalClient->toArray();
228+
$clientData['allowed_origin'] = $clientAllowedOrigins;
229+
$form->setDefaults($clientData);
230+
231+
if ($form->isSuccess()) {
232+
$updatedAt = $this->helpers->dateTime()->getUtc();
233+
234+
$updatedClient = $this->buildClientEntityFromFormData(
235+
$form,
236+
$originalClient->getIdentifier(),
237+
$originalClient->getSecret(),
238+
$originalClient->getRegistrationType(),
239+
$updatedAt,
240+
$originalClient->getCreatedAt(),
241+
$originalClient->getExpiresAt(),
242+
$originalClient->getOwner(),
243+
);
244+
245+
// TODO mivanci Check if the entity identifier already exists for other client.
246+
247+
$this->clientRepository->update($updatedClient);
248+
249+
// Also persist allowed origins for this client.
250+
is_array($allowedOrigins = $form->getValues('array')['allowed_origin'] ?? []) ||
251+
throw new OidcException('Unexpected value for allowed origins.');
252+
/** @var string[] $allowedOrigins */
253+
$this->allowedOriginRepository->set($originalClient->getIdentifier(), $allowedOrigins);
254+
255+
$this->sessionMessagesService->addMessage(Translate::noop('Client has been updated.'));
256+
257+
return $this->routes->getRedirectResponseToModuleUrl(
258+
RoutesEnum::AdminClientsShow->value,
259+
[ParametersEnum::ClientId->value => $originalClient->getIdentifier()],
260+
);
261+
}
262+
263+
return $this->templateFactory->build(
264+
'oidc:clients/edit.twig',
265+
[
266+
'originalClient' => $originalClient,
267+
'form' => $form,
268+
'actionRoute' => $this->routes->urlAdminClientsEdit($originalClient->getIdentifier()),
269+
'regexUri' => ClientForm::REGEX_URI,
270+
'regexAllowedOriginUrl' => ClientForm::REGEX_ALLOWED_ORIGIN_URL,
271+
'regexHttpUri' => ClientForm::REGEX_HTTP_URI,
272+
'regexHttpUriPath' => ClientForm::REGEX_HTTP_URI_PATH,
273+
],
274+
RoutesEnum::AdminClients->value,
275+
);
276+
}
277+
212278
/**
213279
* TODO mivanci Move to ClientEntityFactory::fromRegistrationData on dynamic client registration implementation.
214280
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
215281
*/
216-
protected function buildClientFromFormData(
282+
protected function buildClientEntityFromFormData(
217283
Form $form,
218284
string $identifier,
219285
string $secret,

0 commit comments

Comments
 (0)