WebAuthn.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 string */
  18. private $uid;
  19. /** @var IInitialStateService */
  20. private $initialStateService;
  21. /** @var Manager */
  22. private $manager;
  23. public function __construct(PublicKeyCredentialMapper $mapper,
  24. string $UserId,
  25. IInitialStateService $initialStateService,
  26. Manager $manager) {
  27. $this->mapper = $mapper;
  28. $this->uid = $UserId;
  29. $this->initialStateService = $initialStateService;
  30. $this->manager = $manager;
  31. }
  32. public function getForm() {
  33. $this->initialStateService->provideInitialState(
  34. Application::APP_ID,
  35. 'webauthn-devices',
  36. $this->mapper->findAllForUid($this->uid)
  37. );
  38. return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
  39. ]);
  40. }
  41. public function getSection(): ?string {
  42. if (!$this->manager->isWebAuthnAvailable()) {
  43. return null;
  44. }
  45. return 'security';
  46. }
  47. public function getPriority(): int {
  48. return 20;
  49. }
  50. }