mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Passkeys: agents and client portal contacts can add a passkey with their password and sign in with it instead of their email and password, counting as two-step sign-in; a passkey that supports PRF also opens an agent's credential vault, otherwise credentials stay locked until they type their password once; admins can turn passkeys off in Security settings, and resetting MFA, turning off a contact's two-step sign-in, archiving an agent and the incident password reset remove them; database 4.2.2 adds user_passkeys, users.user_passkey_handle and settings.config_login_passkeys, and lbuchs/WebAuthn 2.2.0 is bundled in libs/webauthn
This commit is contained in:
@@ -629,6 +629,80 @@ if (isset($_POST['portal_password_change'])) {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Passkeys (functions/passkey.php, js/passkey.js) - their password is checked before the browser
|
||||
* makes one (passkey_create_options, JSON), so a typo doesn't leave one on their device that
|
||||
* doesn't work here; the passkey then comes back with the form (portal_passkey_add).
|
||||
*/
|
||||
if (isset($_POST['passkey_create_options'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!passkeysOn() || $session_auth_method !== 'local') {
|
||||
http_response_code(403);
|
||||
exit(json_encode(['error' => 'Passkeys can\'t be added to this account.']));
|
||||
}
|
||||
[$password_ok, $password_message, $me] = passkeyPasswordCheck($session_user_id, (string) ($_POST['current_password'] ?? ''), 'add a passkey in the client portal');
|
||||
if (!$password_ok) {
|
||||
exit(json_encode(['error' => $password_message]));
|
||||
}
|
||||
echo json_encode(passkeyCreateOptions($session_user_id, $me['user_email'], stripslashes($session_contact_name)));
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['portal_passkey_add'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
if (!passkeysOn() || $session_auth_method !== 'local') {
|
||||
redirect('profile.php');
|
||||
}
|
||||
[$password_ok, $password_message] = passkeyPasswordCheck($session_user_id, (string) ($_POST['current_password'] ?? ''), 'add a passkey in the client portal');
|
||||
if (!$password_ok) {
|
||||
flashAlert($password_message, 'error');
|
||||
redirect('profile.php#security');
|
||||
}
|
||||
|
||||
$name = trim((string) ($_POST['passkey_name'] ?? ''));
|
||||
if ($name === '') {
|
||||
$name = passkeyDefaultName($_SERVER['HTTP_USER_AGENT'] ?? '');
|
||||
}
|
||||
$name = mb_substr($name, 0, PASSKEY_NAME_MAX);
|
||||
|
||||
[$passkey_id, $how] = passkeyRegister($session_user_id, $name, [
|
||||
'client_data' => $_POST['passkey_client_data'] ?? '',
|
||||
'attestation' => $_POST['passkey_attestation'] ?? '',
|
||||
'transports' => $_POST['passkey_transports'] ?? '',
|
||||
]);
|
||||
if (!$passkey_id) {
|
||||
flashAlert(escapeHtml($how), 'error');
|
||||
redirect('profile.php#security');
|
||||
}
|
||||
|
||||
logAudit("Contact", "Edit", "Client contact $session_contact_name added a passkey (" . escapeSql($name) . ") in the client portal", $session_client_id, $session_contact_id);
|
||||
portalMailAccountChange(stripslashes($session_contact_email), stripslashes($session_contact_name), 'passkey_added');
|
||||
|
||||
flashAlert("Passkey <strong>" . escapeHtml($name) . "</strong> added - sign in with it next time, no password needed");
|
||||
redirect('profile.php#security');
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['portal_passkey_remove'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$name = passkeyDelete($session_user_id, intval($_GET['portal_passkey_remove']));
|
||||
if ($name !== false) {
|
||||
logAudit("Contact", "Edit", "Client contact $session_contact_name removed a passkey (" . escapeSql($name) . ") in the client portal", $session_client_id, $session_contact_id);
|
||||
portalMailAccountChange(stripslashes($session_contact_email), stripslashes($session_contact_name), 'passkey_removed');
|
||||
flashAlert("Passkey <strong>" . escapeHtml($name) . "</strong> removed - it no longer signs you in");
|
||||
}
|
||||
redirect('profile.php#security');
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['portal_mfa_enable'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
Reference in New Issue
Block a user