Skip to content

Commit 260dec9

Browse files
committed
WIP Move to SSP UI
1 parent 76073b5 commit 260dec9

File tree

15 files changed

+584
-328
lines changed

15 files changed

+584
-328
lines changed

public/assets/css/src/default.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ table.client-table {
112112
width: 25%;
113113
font-weight: bolder;
114114
}
115+
116+
.confirm-action {}

public/assets/js/src/default.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
(function() {
3+
4+
// Attach `confirm-action` click event to all elements with the `confirm-action` class.
5+
document.querySelectorAll('.confirm-action').forEach(button => {
6+
button.addEventListener('click', function (event) {
7+
// Get custom confirmation text
8+
const confirmText = this.getAttribute('data-confirm-text') ?? 'Are you sure?';
9+
// Optional: Retrieve additional data
10+
const itemId = this.getAttribute('data-confirm-id') ?? 'N/A';
11+
12+
if (!confirm(confirmText)) {
13+
// Prevent the default action if the user cancels
14+
event.preventDefault();
15+
} else {
16+
// Optional: Handle confirmed action
17+
console.log(
18+
`Confirmed action "${confirmText}" for item with ID "${itemId}"`);
19+
}
20+
});
21+
});
22+
})();

routing/routes/routes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
->controller([ClientController::class, 'index']);
4444
$routes->add(RoutesEnum::AdminClientsShow->name, RoutesEnum::AdminClientsShow->value)
4545
->controller([ClientController::class, 'show']);
46+
$routes->add(RoutesEnum::AdminClientsResetSecret->name, RoutesEnum::AdminClientsResetSecret->value)
47+
->controller([ClientController::class, 'resetSecret'])
48+
->methods([HttpMethodsEnum::POST->value]);
4649

4750
/*****************************************************************************************************************
4851
* OpenID Connect

src/Codebooks/ParametersEnum.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Codebooks;
6+
7+
enum ParametersEnum: string
8+
{
9+
case ClientId = 'client_id';
10+
}

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 AdminClientsResetSecret = 'admin/clients/reset-secret';
2223

2324
/*****************************************************************************************************************
2425
* OpenID Connect

src/Controllers/Admin/ClientController.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
namespace SimpleSAML\Module\oidc\Controllers\Admin;
66

7+
use SimpleSAML\Locale\Translate;
78
use SimpleSAML\Module\oidc\Admin\Authorization;
9+
use SimpleSAML\Module\oidc\Bridges\SspBridge;
10+
use SimpleSAML\Module\oidc\Codebooks\ParametersEnum;
811
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
912
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
1013
use SimpleSAML\Module\oidc\Exceptions\OidcException;
1114
use SimpleSAML\Module\oidc\Factories\TemplateFactory;
1215
use SimpleSAML\Module\oidc\Repositories\AllowedOriginRepository;
1316
use SimpleSAML\Module\oidc\Repositories\ClientRepository;
1417
use SimpleSAML\Module\oidc\Services\AuthContextService;
18+
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
19+
use SimpleSAML\Module\oidc\Utils\Routes;
1520
use Symfony\Component\HttpFoundation\Request;
1621
use Symfony\Component\HttpFoundation\Response;
1722

@@ -22,6 +27,9 @@ public function __construct(
2227
protected readonly Authorization $authorization,
2328
protected readonly ClientRepository $clientRepository,
2429
protected readonly AllowedOriginRepository $allowedOriginRepository,
30+
protected readonly SspBridge $sspBridge,
31+
protected readonly SessionMessagesService $sessionMessagesService,
32+
protected readonly Routes $routes,
2533
) {
2634
$this->authorization->requireAdminOrUserWithPermission(AuthContextService::PERM_CLIENT);
2735
}
@@ -33,7 +41,7 @@ public function __construct(
3341
*/
3442
protected function getClientFromRequest(Request $request): ClientEntityInterface
3543
{
36-
($clientId = $request->query->getString('client_id'))
44+
($clientId = $request->query->getString(ParametersEnum::ClientId->value))
3745
|| throw new OidcException('Client ID not provided.');
3846

3947
$authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();
@@ -50,7 +58,6 @@ public function index(Request $request): Response
5058

5159
$pagination = $this->clientRepository->findPaginated($page, $query, $authedUserId);
5260

53-
5461
return $this->templateFactory->build(
5562
'oidc:clients.twig',
5663
[
@@ -71,14 +78,39 @@ public function show(Request $request): Response
7178
$client = $this->getClientFromRequest($request);
7279
$allowedOrigins = $this->allowedOriginRepository->get($client->getIdentifier());
7380

74-
// TODO mivanci rename *-ssp.twig templates after removing old ones.
7581
return $this->templateFactory->build(
76-
'oidc:clients/show-ssp.twig',
82+
'oidc:clients/show.twig',
7783
[
7884
'client' => $client,
7985
'allowedOrigins' => $allowedOrigins,
8086
],
8187
RoutesEnum::AdminClients->value,
8288
);
8389
}
90+
91+
/**
92+
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
93+
*/
94+
public function resetSecret(Request $request): Response
95+
{
96+
$client = $this->getClientFromRequest($request);
97+
98+
$oldSecret = $request->request->get('secret');
99+
100+
if ($oldSecret !== $client->getSecret()) {
101+
throw new OidcException('Client secret does not match.');
102+
}
103+
104+
$client->restoreSecret($this->sspBridge->utils()->random()->generateID());
105+
$authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();
106+
$this->clientRepository->update($client, $authedUserId);
107+
108+
$message = Translate::noop('Client secret has been reset.');
109+
$this->sessionMessagesService->addMessage($message);
110+
111+
return $this->routes->getRedirectResponseToModuleUrl(
112+
RoutesEnum::AdminClientsShow->value,
113+
[ParametersEnum::ClientId->value => $client->getIdentifier()],
114+
);
115+
}
84116
}

src/Controllers/Admin/ConfigController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use SimpleSAML\Module\oidc\ModuleConfig;
1212
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
1313
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
14+
use SimpleSAML\Module\oidc\Utils\Routes;
1415
use SimpleSAML\OpenID\Federation;
15-
use Symfony\Component\HttpFoundation\RedirectResponse;
1616
use Symfony\Component\HttpFoundation\Response;
1717

1818
class ConfigController
@@ -24,6 +24,7 @@ public function __construct(
2424
protected readonly DatabaseMigration $databaseMigration,
2525
protected readonly SessionMessagesService $sessionMessagesService,
2626
protected readonly Federation $federation,
27+
protected readonly Routes $routes,
2728
) {
2829
$this->authorization->requireAdmin(true);
2930
}
@@ -44,14 +45,14 @@ public function runMigrations(): Response
4445
if ($this->databaseMigration->isMigrated()) {
4546
$message = Translate::noop('Database is already migrated.');
4647
$this->sessionMessagesService->addMessage($message);
47-
return new RedirectResponse($this->moduleConfig->getModuleUrl(RoutesEnum::AdminMigrations->value));
48+
return $this->routes->getRedirectResponseToModuleUrl(RoutesEnum::AdminMigrations->value);
4849
}
4950

5051
$this->databaseMigration->migrate();
5152
$message = Translate::noop('Database migrated successfully.');
5253
$this->sessionMessagesService->addMessage($message);
5354

54-
return new RedirectResponse($this->moduleConfig->getModuleUrl(RoutesEnum::AdminMigrations->value));
55+
return $this->routes->getRedirectResponseToModuleUrl(RoutesEnum::AdminMigrations->value);
5556
}
5657

5758
public function protocolSettings(): Response

src/Controllers/Client/ShowController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __invoke(ServerRequest $request): Template
4949
$client = $this->getClientFromRequest($request);
5050
$allowedOrigins = $this->allowedOriginRepository->get($client->getIdentifier());
5151

52-
return $this->templateFactory->build('oidc:clients/show.twig', [
52+
return $this->templateFactory->build('oidc:clients/show-old.twig', [
5353
'client' => $client,
5454
'allowedOrigins' => $allowedOrigins,
5555
]);

src/Utils/Routes.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use SimpleSAML\Module\oidc\Bridges\SspBridge;
88
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
99
use SimpleSAML\Module\oidc\ModuleConfig;
10+
use Symfony\Component\HttpFoundation\RedirectResponse;
1011

1112
class Routes
1213
{
@@ -23,6 +24,19 @@ public function getModuleUrl(string $resource = '', array $parameters = []): str
2324
return $this->sspBridge->module()->getModuleUrl($resource, $parameters);
2425
}
2526

27+
public function getRedirectResponseToModuleUrl(
28+
string $resource = '',
29+
array $parameters = [],
30+
int $status = 302,
31+
array $headers = [],
32+
): RedirectResponse {
33+
return new RedirectResponse(
34+
$this->getModuleUrl($resource, $parameters),
35+
$status,
36+
$headers,
37+
);
38+
}
39+
2640
/*****************************************************************************************************************
2741
* Admin area
2842
****************************************************************************************************************/
@@ -60,6 +74,12 @@ public function urlAdminClientsShow(string $clientId, array $parameters = []): s
6074
return $this->getModuleUrl(RoutesEnum::AdminClientsShow->value, $parameters);
6175
}
6276

77+
public function urlAdminClientsResetSecret(string $clientId, array $parameters = []): string
78+
{
79+
$parameters['client_id'] = $clientId;
80+
return $this->getModuleUrl(RoutesEnum::AdminClientsResetSecret->value, $parameters);
81+
}
82+
6383
/*****************************************************************************************************************
6484
* OpenID Connect
6585
****************************************************************************************************************/

templates/base.twig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
{% endblock content -%}
4040

41-
{% block postload %}{% endblock postload %}
41+
{% block postload %}
42+
43+
{{ parent() }}
44+
45+
<script src="{{ asset('js/src/default.js', 'oidc') }}"></script>
46+
{% endblock postload %}
4247

4348
{% block oidcPostload %}{% endblock %}

0 commit comments

Comments
 (0)