Admin.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\OAuth2\Settings;
  26. use OCA\OAuth2\Db\ClientMapper;
  27. use OCP\AppFramework\Http\TemplateResponse;
  28. use OCP\AppFramework\Services\IInitialState;
  29. use OCP\IURLGenerator;
  30. use OCP\Security\ICrypto;
  31. use OCP\Settings\ISettings;
  32. use Psr\Log\LoggerInterface;
  33. class Admin implements ISettings {
  34. public function __construct(
  35. private IInitialState $initialState,
  36. private ClientMapper $clientMapper,
  37. private IURLGenerator $urlGenerator,
  38. private ICrypto $crypto,
  39. private LoggerInterface $logger,
  40. ) {
  41. }
  42. public function getForm(): TemplateResponse {
  43. $clients = $this->clientMapper->getClients();
  44. $result = [];
  45. foreach ($clients as $client) {
  46. try {
  47. $secret = $this->crypto->decrypt($client->getSecret());
  48. $result[] = [
  49. 'id' => $client->getId(),
  50. 'name' => $client->getName(),
  51. 'redirectUri' => $client->getRedirectUri(),
  52. 'clientId' => $client->getClientIdentifier(),
  53. 'clientSecret' => $secret,
  54. ];
  55. } catch (\Exception $e) {
  56. $this->logger->error('[Settings] OAuth client secret decryption error', ['exception' => $e]);
  57. }
  58. }
  59. $this->initialState->provideInitialState('clients', $result);
  60. $this->initialState->provideInitialState('oauth2-doc-link', $this->urlGenerator->linkToDocs('admin-oauth2'));
  61. return new TemplateResponse(
  62. 'oauth2',
  63. 'admin',
  64. [],
  65. ''
  66. );
  67. }
  68. public function getSection(): string {
  69. return 'security';
  70. }
  71. public function getPriority(): int {
  72. return 100;
  73. }
  74. }