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:
johnnyq
2026-11-28 23:31:17 -05:00
parent 4a2933cac9
commit d9c1c752bd
50 changed files with 4679 additions and 46 deletions

View File

@@ -121,7 +121,9 @@ if (!$portal_view_as) {
// not set up yet: Your account until it is, and nothing else. The one gate for the
// pages and for client/post.php, judged on the script really running and every key
// in the request (requestIsMfaSetup()).
$portal_mfa_setup_needed = !$portal_view_as && intval($config_client_portal_require_mfa ?? 0) === 1 && $session_auth_method === 'local' && !$session_mfa_on;
// A passkey sign-in is two-step sign-in already (functions/passkey.php)
$portal_mfa_setup_needed = !$portal_view_as && intval($config_client_portal_require_mfa ?? 0) === 1 && $session_auth_method === 'local' && !$session_mfa_on
&& ($_SESSION['signed_in_with'] ?? '') !== 'passkey';
if ($portal_mfa_setup_needed && !requestIsMfaSetup([
'client/profile.php' => [[['mfa'], []]],
'client/post.php' => [[[], ['csrf_token', 'portal_mfa_enable', 'verify_code']], [['logout'], []]],

View File

@@ -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();

View File

@@ -35,6 +35,10 @@ $microsoft_account = $session_auth_method === 'azure';
$mfa_required = intval($config_client_portal_require_mfa) === 1;
$mfa_setup = $password_account && !$session_mfa_on && (($_GET['mfa'] ?? '') === 'setup' || $portal_mfa_setup_needed) && !portalViewingAs();
$remembered = $session_mfa_on ? portalRememberedBrowsers($session_user_id) : 0;
// Passkeys, once the database has them (functions/passkey.php)
$passkeys_ready = $password_account && passkeysReady();
$passkeys_on = $passkeys_ready && passkeysOn();
$my_passkeys = $passkeys_ready ? passkeyList($session_user_id) : [];
$sees_company = $session_contact_primary || $session_contact_is_technical_contact; // they see every ticket at their company
// Setting up two-step sign-in: one secret, kept until a code from it is checked
@@ -334,6 +338,60 @@ $csrf = escapeHtml($_SESSION['csrf_token']);
<div class="itflow-portal-panel-body border-top small text-body-secondary py-2"><?= escapeHtml($session_company_name) ?> asks everyone to use it, so it stays on. Lost your phone? Ask us to reset it.</div>
<?php } ?>
<?php if ($passkeys_ready && ($passkeys_on || $my_passkeys)) { ?>
<!-- Passkeys - signing in without the password (js/passkey.js) -->
<ul class="itflow-portal-list border-top">
<li class="itflow-portal-ticket">
<?= portalTile('fa-fingerprint') ?>
<span class="itflow-portal-ticket-main">
<span class="itflow-portal-ticket-subject d-block">Passkeys</span>
<span class="itflow-portal-ticket-meta"><span><?= $my_passkeys ? 'Sign in with your fingerprint, face or PIN - no password needed' : 'Sign in with your fingerprint, face or PIN instead of your password' ?></span></span>
</span>
<?php if ($passkeys_on && !portalViewingAs()) { ?>
<button type="button" class="btn btn-sm btn-primary text-nowrap" data-bs-toggle="collapse" data-bs-target="#passkeyForm" aria-expanded="false" aria-controls="passkeyForm">Add</button>
<?php } ?>
</li>
<?php foreach ($my_passkeys as $passkey) { ?>
<li class="itflow-portal-ticket">
<span class="itflow-portal-ticket-main ps-1">
<span class="itflow-portal-ticket-subject d-block text-truncate"><i class="fas fa-fw fa-key text-body-secondary me-1"></i><?= escapeHtml($passkey['passkey_name']) ?></span>
<span class="itflow-portal-ticket-meta"><span><?= passkeyMetaHtml($passkey, false) ?></span></span>
</span>
<?php if (!portalViewingAs()) { ?>
<a class="btn btn-sm btn-outline-secondary text-nowrap confirm-link" href="post.php?portal_passkey_remove=<?= intval($passkey['passkey_id']) ?>&csrf_token=<?= $csrf ?>">Remove</a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php if ($passkeys_on && !portalViewingAs()) { ?>
<form class="collapse itflow-portal-panel-body border-top" id="passkeyForm" action="post.php" method="post" autocomplete="off" data-passkey-add data-options-url="post.php" data-csrf="<?= $csrf ?>">
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
<input type="hidden" name="portal_passkey_add" value="1">
<input type="hidden" name="passkey_client_data" value="">
<input type="hidden" name="passkey_attestation" value="">
<input type="hidden" name="passkey_transports" value="">
<input type="hidden" name="passkey_prf" value="">
<p class="small text-body-secondary">Your browser asks where to keep it - this device, your phone, a security key or your password manager - and for your fingerprint, face or PIN.</p>
<div data-passkey-message></div>
<div class="mb-3">
<label class="form-label" for="passkeyName">Name</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-tag"></i></span>
<input type="text" class="form-control" id="passkeyName" name="passkey_name" maxlength="<?= PASSKEY_NAME_MAX ?>" placeholder="<?= escapeHtml(passkeyDefaultName($_SERVER['HTTP_USER_AGENT'] ?? '')) ?>">
</div>
</div>
<div class="mb-3">
<label class="form-label" for="passkeyPassword">Your current password</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-lock"></i></span>
<input type="password" class="form-control" id="passkeyPassword" name="current_password" autocomplete="current-password" required>
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-fingerprint me-2"></i>Add Passkey</button>
</form>
<?php } ?>
<?php } ?>
<?php if ($session_mfa_on && $remembered) { ?>
<form class="itflow-portal-panel-body border-top d-flex align-items-center justify-content-between gap-2" action="post.php" method="post" data-portal-once>
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
@@ -402,4 +460,8 @@ $csrf = escapeHtml($_SESSION['csrf_token']);
</div>
<?php
if ($passkeys_on) { ?>
<script src="<?= staticFileUrl('/js/passkey.js') ?>"></script>
<?php }
require_once 'includes/footer.php';