1
0

Admin.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Security\ICrypto;
  13. use OCP\Settings\ISettings;
  14. use Psr\Log\LoggerInterface;
  15. class Admin implements ISettings {
  16. public function __construct(
  17. private IInitialState $initialState,
  18. private ClientMapper $clientMapper,
  19. private IURLGenerator $urlGenerator,
  20. private ICrypto $crypto,
  21. private LoggerInterface $logger,
  22. ) {
  23. }
  24. public function getForm(): TemplateResponse {
  25. $clients = $this->clientMapper->getClients();
  26. $result = [];
  27. foreach ($clients as $client) {
  28. try {
  29. $secret = $this->crypto->decrypt($client->getSecret());
  30. $result[] = [
  31. 'id' => $client->getId(),
  32. 'name' => $client->getName(),
  33. 'redirectUri' => $client->getRedirectUri(),
  34. 'clientId' => $client->getClientIdentifier(),
  35. 'clientSecret' => $secret,
  36. ];
  37. } catch (\Exception $e) {
  38. $this->logger->error('[Settings] OAuth client secret decryption error', ['exception' => $e]);
  39. }
  40. }
  41. $this->initialState->provideInitialState('clients', $result);
  42. $this->initialState->provideInitialState('oauth2-doc-link', $this->urlGenerator->linkToDocs('admin-oauth2'));
  43. return new TemplateResponse(
  44. 'oauth2',
  45. 'admin',
  46. [],
  47. ''
  48. );
  49. }
  50. public function getSection(): string {
  51. return 'security';
  52. }
  53. public function getPriority(): int {
  54. return 100;
  55. }
  56. }