Admin.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Settings\ISettings;
  30. use OCP\IURLGenerator;
  31. class Admin implements ISettings {
  32. private IInitialState $initialState;
  33. private ClientMapper $clientMapper;
  34. private IURLGenerator $urlGenerator;
  35. public function __construct(
  36. IInitialState $initialState,
  37. ClientMapper $clientMapper,
  38. IURLGenerator $urlGenerator
  39. ) {
  40. $this->initialState = $initialState;
  41. $this->clientMapper = $clientMapper;
  42. $this->urlGenerator = $urlGenerator;
  43. }
  44. public function getForm(): TemplateResponse {
  45. $clients = $this->clientMapper->getClients();
  46. $result = [];
  47. foreach ($clients as $client) {
  48. $result[] = [
  49. 'id' => $client->getId(),
  50. 'name' => $client->getName(),
  51. 'redirectUri' => $client->getRedirectUri(),
  52. 'clientId' => $client->getClientIdentifier(),
  53. 'clientSecret' => $client->getSecret(),
  54. ];
  55. }
  56. $this->initialState->provideInitialState('clients', $result);
  57. $this->initialState->provideInitialState('oauth2-doc-link', $this->urlGenerator->linkToDocs('admin-oauth2'));
  58. return new TemplateResponse(
  59. 'oauth2',
  60. 'admin',
  61. [],
  62. ''
  63. );
  64. }
  65. public function getSection(): string {
  66. return 'security';
  67. }
  68. public function getPriority(): int {
  69. return 100;
  70. }
  71. }