- md5
- af770018776973d337f3b8154de249f2
- sha1
- 1e6c290b0aa6d24fc9e78df6dc6414da947c9da9
- sha256
- c8ca29a7e7fb1a940554e7abd6fd7575db5388488eb535f4185bd6fd501a4715
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
<?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 Exception;
use Joomla\CMS\Event\Plugin\System\Webauthn\AjaxDelete;
use Joomla\CMS\User\User;
use Joomla\Event\Event;
/**
* Ajax handler for akaction=savelabel
*
* 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()->input;
$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 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.