WebAuthn.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Settings\Personal\Security;
  8. use OC\Authentication\WebAuthn\Db\PublicKeyCredentialMapper;
  9. use OC\Authentication\WebAuthn\Manager;
  10. use OCA\Settings\AppInfo\Application;
  11. use OCP\AppFramework\Http\TemplateResponse;
  12. use OCP\IInitialStateService;
  13. use OCP\Settings\ISettings;
  14. class WebAuthn implements ISettings {
  15. /** @var PublicKeyCredentialMapper */
  16. private $mapper;
  17. /** @var Manager */
  18. private $manager;
  19. public function __construct(
  20. PublicKeyCredentialMapper $mapper,
  21. private string $userId,
  22. private IInitialStateService $initialStateService,
  23. Manager $manager,
  24. ) {
  25. $this->mapper = $mapper;
  26. $this->manager = $manager;
  27. }
  28. public function getForm() {
  29. $this->initialStateService->provideInitialState(
  30. Application::APP_ID,
  31. 'webauthn-devices',
  32. $this->mapper->findAllForUid($this->userId)
  33. );
  34. return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
  35. ]);
  36. }
  37. public function getSection(): ?string {
  38. if (!$this->manager->isWebAuthnAvailable()) {
  39. return null;
  40. }
  41. return 'security';
  42. }
  43. public function getPriority(): int {
  44. return 20;
  45. }
  46. }