@@ -38,81 +38,81 @@ |
||
38 | 38 | use Webauthn\PublicKeyCredentialCreationOptions; |
39 | 39 | |
40 | 40 | class WebAuthnController extends Controller { |
41 | - private const WEBAUTHN_REGISTRATION = 'webauthn_registration'; |
|
42 | - |
|
43 | - /** @var Manager */ |
|
44 | - private $manager; |
|
45 | - |
|
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
48 | - /** |
|
49 | - * @var ISession |
|
50 | - */ |
|
51 | - private $session; |
|
52 | - /** |
|
53 | - * @var ILogger |
|
54 | - */ |
|
55 | - private $logger; |
|
56 | - |
|
57 | - public function __construct(IRequest $request, ILogger $logger, Manager $webAuthnManager, IUserSession $userSession, ISession $session) { |
|
58 | - parent::__construct(Application::APP_ID, $request); |
|
59 | - |
|
60 | - $this->manager = $webAuthnManager; |
|
61 | - $this->userSession = $userSession; |
|
62 | - $this->session = $session; |
|
63 | - $this->logger = $logger; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @NoAdminRequired |
|
68 | - * @NoSubadminRequired |
|
69 | - * @PasswordConfirmationRequired |
|
70 | - * @UseSession |
|
71 | - * @NoCSRFRequired |
|
72 | - */ |
|
73 | - public function startRegistration(): JSONResponse { |
|
74 | - $this->logger->debug('Starting WebAuthn registration'); |
|
75 | - |
|
76 | - $credentialOptions = $this->manager->startRegistration($this->userSession->getUser(), $this->request->getServerHost()); |
|
77 | - |
|
78 | - // Set this in the session since we need it on finish |
|
79 | - $this->session->set(self::WEBAUTHN_REGISTRATION, $credentialOptions); |
|
80 | - |
|
81 | - return new JSONResponse($credentialOptions); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @NoAdminRequired |
|
86 | - * @NoSubadminRequired |
|
87 | - * @PasswordConfirmationRequired |
|
88 | - * @UseSession |
|
89 | - */ |
|
90 | - public function finishRegistration(string $name, string $data): JSONResponse { |
|
91 | - $this->logger->debug('Finishing WebAuthn registration'); |
|
92 | - |
|
93 | - if (!$this->session->exists(self::WEBAUTHN_REGISTRATION)) { |
|
94 | - $this->logger->debug('Trying to finish WebAuthn registration without session data'); |
|
95 | - return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
96 | - } |
|
97 | - |
|
98 | - // Obtain the publicKeyCredentialOptions from when we started the registration |
|
99 | - $publicKeyCredentialCreationOptions = PublicKeyCredentialCreationOptions::createFromArray($this->session->get(self::WEBAUTHN_REGISTRATION)); |
|
100 | - |
|
101 | - $this->session->remove(self::WEBAUTHN_REGISTRATION); |
|
102 | - |
|
103 | - return new JSONResponse($this->manager->finishRegister($publicKeyCredentialCreationOptions, $name, $data)); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @NoAdminRequired |
|
108 | - * @NoSubadminRequired |
|
109 | - * @PasswordConfirmationRequired |
|
110 | - */ |
|
111 | - public function deleteRegistration(int $id): JSONResponse { |
|
112 | - $this->logger->debug('Finishing WebAuthn registration'); |
|
113 | - |
|
114 | - $this->manager->deleteRegistration($this->userSession->getUser(), $id); |
|
115 | - |
|
116 | - return new JSONResponse([]); |
|
117 | - } |
|
41 | + private const WEBAUTHN_REGISTRATION = 'webauthn_registration'; |
|
42 | + |
|
43 | + /** @var Manager */ |
|
44 | + private $manager; |
|
45 | + |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | + /** |
|
49 | + * @var ISession |
|
50 | + */ |
|
51 | + private $session; |
|
52 | + /** |
|
53 | + * @var ILogger |
|
54 | + */ |
|
55 | + private $logger; |
|
56 | + |
|
57 | + public function __construct(IRequest $request, ILogger $logger, Manager $webAuthnManager, IUserSession $userSession, ISession $session) { |
|
58 | + parent::__construct(Application::APP_ID, $request); |
|
59 | + |
|
60 | + $this->manager = $webAuthnManager; |
|
61 | + $this->userSession = $userSession; |
|
62 | + $this->session = $session; |
|
63 | + $this->logger = $logger; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @NoAdminRequired |
|
68 | + * @NoSubadminRequired |
|
69 | + * @PasswordConfirmationRequired |
|
70 | + * @UseSession |
|
71 | + * @NoCSRFRequired |
|
72 | + */ |
|
73 | + public function startRegistration(): JSONResponse { |
|
74 | + $this->logger->debug('Starting WebAuthn registration'); |
|
75 | + |
|
76 | + $credentialOptions = $this->manager->startRegistration($this->userSession->getUser(), $this->request->getServerHost()); |
|
77 | + |
|
78 | + // Set this in the session since we need it on finish |
|
79 | + $this->session->set(self::WEBAUTHN_REGISTRATION, $credentialOptions); |
|
80 | + |
|
81 | + return new JSONResponse($credentialOptions); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @NoAdminRequired |
|
86 | + * @NoSubadminRequired |
|
87 | + * @PasswordConfirmationRequired |
|
88 | + * @UseSession |
|
89 | + */ |
|
90 | + public function finishRegistration(string $name, string $data): JSONResponse { |
|
91 | + $this->logger->debug('Finishing WebAuthn registration'); |
|
92 | + |
|
93 | + if (!$this->session->exists(self::WEBAUTHN_REGISTRATION)) { |
|
94 | + $this->logger->debug('Trying to finish WebAuthn registration without session data'); |
|
95 | + return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
96 | + } |
|
97 | + |
|
98 | + // Obtain the publicKeyCredentialOptions from when we started the registration |
|
99 | + $publicKeyCredentialCreationOptions = PublicKeyCredentialCreationOptions::createFromArray($this->session->get(self::WEBAUTHN_REGISTRATION)); |
|
100 | + |
|
101 | + $this->session->remove(self::WEBAUTHN_REGISTRATION); |
|
102 | + |
|
103 | + return new JSONResponse($this->manager->finishRegister($publicKeyCredentialCreationOptions, $name, $data)); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @NoAdminRequired |
|
108 | + * @NoSubadminRequired |
|
109 | + * @PasswordConfirmationRequired |
|
110 | + */ |
|
111 | + public function deleteRegistration(int $id): JSONResponse { |
|
112 | + $this->logger->debug('Finishing WebAuthn registration'); |
|
113 | + |
|
114 | + $this->manager->deleteRegistration($this->userSession->getUser(), $id); |
|
115 | + |
|
116 | + return new JSONResponse([]); |
|
117 | + } |
|
118 | 118 | } |