- md5
- a5261a852fcf7ba4270960db91f87418
- sha1
- 0026a2fc703c7e975ded3ab73a8aff2e81042cde
- sha256
- 74ef2df58bfa99e0c915c36cdedfaedd29bfad713bdc50c01964bed5b930129a
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Webauthn
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\System\Webauthn\PluginTraits;
use Joomla\CMS\Event\Plugin\System\Webauthn\AjaxDelete;
use Joomla\CMS\User\User;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Ajax handler for akaction=delete
*
* Deletes a security key
*
* @since 4.0.0
*/
trait AjaxHandlerDelete
{
/**
* Handle the callback to remove an authenticator
*
* @param AjaxDelete $event The event we are handling
*
* @return void
* @since 4.0.0
*/
public function onAjaxWebauthnDelete(AjaxDelete $event): void
{
// Initialize objects
$input = $this->getApplication()->getInput();
$repository = $this->authenticationHelper->getCredentialsRepository();
// Retrieve data from the request
$credentialId = $input->getBase64('credential_id', '');
// Is this a valid credential?
if (empty($credentialId)) {
$event->addResult(false);
return;
}
$credentialId = base64_decode($credentialId);
if (empty($credentialId) || !$repository->has($credentialId)) {
$event->addResult(false);
return;
}
// Make sure I am editing my own key
try {
$user = $this->getApplication()->getIdentity() ?? new User();
$credentialHandle = $repository->getUserHandleFor($credentialId);
$myHandle = $repository->getHandleFromUserId($user->id);
} catch (\Exception $e) {
$event->addResult(false);
return;
}
if ($credentialHandle !== $myHandle) {
$event->addResult(false);
return;
}
// Delete the record
try {
$repository->remove($credentialId);
} catch (\Exception $e) {
$event->addResult(false);
return;
}
$event->addResult(true);
}
}
The same content is in 31 releases, Joomla 4.4.0-beta3 to 4.4.14. See them all, or every version of this file.