1
0

Admin.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\OAuth2\Settings;
  8. use OCA\OAuth2\Db\ClientMapper;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\IURLGenerator;
  12. use OCP\Settings\ISettings;
  13. use Psr\Log\LoggerInterface;
  14. class Admin implements ISettings {
  15. public function __construct(
  16. private IInitialState $initialState,
  17. private ClientMapper $clientMapper,
  18. private IURLGenerator $urlGenerator,
  19. private LoggerInterface $logger,
  20. ) {
  21. }
  22. public function getForm(): TemplateResponse {
  23. $clients = $this->clientMapper->getClients();
  24. $result = [];
  25. foreach ($clients as $client) {
  26. try {
  27. $result[] = [
  28. 'id' => $client->getId(),
  29. 'name' => $client->getName(),
  30. 'redirectUri' => $client->getRedirectUri(),
  31. 'clientId' => $client->getClientIdentifier(),
  32. 'clientSecret' => '',
  33. ];
  34. } catch (\Exception $e) {
  35. $this->logger->error('[Settings] OAuth client secret decryption error', ['exception' => $e]);
  36. }
  37. }
  38. $this->initialState->provideInitialState('clients', $result);
  39. $this->initialState->provideInitialState('oauth2-doc-link', $this->urlGenerator->linkToDocs('admin-oauth2'));
  40. return new TemplateResponse(
  41. 'oauth2',
  42. 'admin',
  43. [],
  44. ''
  45. );
  46. }
  47. public function getSection(): string {
  48. return 'security';
  49. }
  50. public function getPriority(): int {
  51. return 100;
  52. }
  53. }