diff --git a/core/Controller/WebAuthnController.php b/core/Controller/WebAuthnController.php index 3e986d34b7775..b39a6fdb5e4ce 100644 --- a/core/Controller/WebAuthnController.php +++ b/core/Controller/WebAuthnController.php @@ -21,6 +21,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; use OCP\ISession; +use OCP\IUserManager; use OCP\Util; use Psr\Log\LoggerInterface; use Webauthn\PublicKeyCredentialRequestOptions; @@ -28,6 +29,7 @@ class WebAuthnController extends Controller { private const string WEBAUTHN_LOGIN = 'webauthn_login'; private const string WEBAUTHN_LOGIN_UID = 'webauthn_login_uid'; + private const string WEBAUTHN_LOGIN_NAME = 'webauthn_login_name'; public function __construct( string $appName, @@ -37,6 +39,7 @@ public function __construct( private LoggerInterface $logger, private WebAuthnChain $webAuthnChain, private URLGenerator $urlGenerator, + private IUserManager $userManager, ) { parent::__construct($appName, $request); } @@ -59,6 +62,7 @@ public function startAuthentication(string $loginName): JSONResponse { $publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost()); $this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions)); $this->session->set(self::WEBAUTHN_LOGIN_UID, $uid); + $this->session->set(self::WEBAUTHN_LOGIN_NAME, $loginName); return new JSONResponse($publicKeyCredentialRequestOptions); } @@ -69,7 +73,10 @@ public function startAuthentication(string $loginName): JSONResponse { public function finishAuthentication(string $data): JSONResponse { $this->logger->debug('Validating WebAuthn login'); - if (!$this->session->exists(self::WEBAUTHN_LOGIN) || !$this->session->exists(self::WEBAUTHN_LOGIN_UID)) { + if (!$this->session->exists(self::WEBAUTHN_LOGIN) + || !$this->session->exists(self::WEBAUTHN_LOGIN_UID) + || !$this->session->exists(self::WEBAUTHN_LOGIN_NAME) + ) { $this->logger->debug('Trying to finish WebAuthn login without session data'); return new JSONResponse([], Http::STATUS_BAD_REQUEST); } @@ -77,14 +84,16 @@ public function finishAuthentication(string $data): JSONResponse { // Obtain the publicKeyCredentialOptions from when we started the registration $publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString($this->session->get(self::WEBAUTHN_LOGIN)); $uid = $this->session->get(self::WEBAUTHN_LOGIN_UID); + $loginName = $this->session->get(self::WEBAUTHN_LOGIN_NAME); $authenticatorData = $this->webAuthnManger->finishAuthentication($publicKeyCredentialRequestOptions, $data, $uid); //TODO: add other parameters $loginData = new LoginData( $this->request, - $uid, + $loginName, '' ); + $loginData->setUser($this->userManager->get($uid)); $loginData->setWebAuthnUserVerified($authenticatorData->isUserVerified()); $this->webAuthnChain->process($loginData); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index be06cdd45b860..aa33a5567ad8d 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1320,7 +1320,6 @@ 'OC\\Authentication\\Login\\UpdateLastPasswordConfirmCommand' => $baseDir . '/lib/private/Authentication/Login/UpdateLastPasswordConfirmCommand.php', 'OC\\Authentication\\Login\\UserDisabledCheckCommand' => $baseDir . '/lib/private/Authentication/Login/UserDisabledCheckCommand.php', 'OC\\Authentication\\Login\\WebAuthnChain' => $baseDir . '/lib/private/Authentication/Login/WebAuthnChain.php', - 'OC\\Authentication\\Login\\WebAuthnLoginCommand' => $baseDir . '/lib/private/Authentication/Login/WebAuthnLoginCommand.php', 'OC\\Authentication\\Notifications\\Notifier' => $baseDir . '/lib/private/Authentication/Notifications/Notifier.php', 'OC\\Authentication\\Token\\INamedToken' => $baseDir . '/lib/private/Authentication/Token/INamedToken.php', 'OC\\Authentication\\Token\\IProvider' => $baseDir . '/lib/private/Authentication/Token/IProvider.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 73277b5502fe1..dcf3ce183fc6a 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1361,7 +1361,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Authentication\\Login\\UpdateLastPasswordConfirmCommand' => __DIR__ . '/../../..' . '/lib/private/Authentication/Login/UpdateLastPasswordConfirmCommand.php', 'OC\\Authentication\\Login\\UserDisabledCheckCommand' => __DIR__ . '/../../..' . '/lib/private/Authentication/Login/UserDisabledCheckCommand.php', 'OC\\Authentication\\Login\\WebAuthnChain' => __DIR__ . '/../../..' . '/lib/private/Authentication/Login/WebAuthnChain.php', - 'OC\\Authentication\\Login\\WebAuthnLoginCommand' => __DIR__ . '/../../..' . '/lib/private/Authentication/Login/WebAuthnLoginCommand.php', 'OC\\Authentication\\Notifications\\Notifier' => __DIR__ . '/../../..' . '/lib/private/Authentication/Notifications/Notifier.php', 'OC\\Authentication\\Token\\INamedToken' => __DIR__ . '/../../..' . '/lib/private/Authentication/Token/INamedToken.php', 'OC\\Authentication\\Token\\IProvider' => __DIR__ . '/../../..' . '/lib/private/Authentication/Token/IProvider.php', diff --git a/lib/private/Authentication/Login/WebAuthnChain.php b/lib/private/Authentication/Login/WebAuthnChain.php index 87027d8a9566b..154e50074f702 100644 --- a/lib/private/Authentication/Login/WebAuthnChain.php +++ b/lib/private/Authentication/Login/WebAuthnChain.php @@ -12,7 +12,6 @@ class WebAuthnChain { public function __construct( private UserDisabledCheckCommand $userDisabledCheckCommand, - private WebAuthnLoginCommand $webAuthnLoginCommand, private LoggedInCheckCommand $loggedInCheckCommand, private CompleteLoginCommand $completeLoginCommand, private CreateSessionTokenCommand $createSessionTokenCommand, @@ -27,7 +26,6 @@ public function __construct( public function process(LoginData $loginData): LoginResult { $chain = $this->userDisabledCheckCommand; $chain - ->setNext($this->webAuthnLoginCommand) ->setNext($this->loggedInCheckCommand) ->setNext($this->completeLoginCommand) ->setNext($this->createSessionTokenCommand) diff --git a/lib/private/Authentication/Login/WebAuthnLoginCommand.php b/lib/private/Authentication/Login/WebAuthnLoginCommand.php deleted file mode 100644 index 0bd64666cecee..0000000000000 --- a/lib/private/Authentication/Login/WebAuthnLoginCommand.php +++ /dev/null @@ -1,30 +0,0 @@ -userManager->get($loginData->getUsername()); - $loginData->setUser($user); - if ($user === null) { - $loginData->setUser(false); - } - - return $this->processNextOrFinishSuccessfully($loginData); - } -}