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:
81
login.php
81
login.php
@@ -107,6 +107,9 @@ $config_login_key_secret = $row['config_login_key_secret'];
|
||||
|
||||
$azure_client_id = $row['config_azure_client_id'] ?? null;
|
||||
|
||||
// Signing in with a passkey (functions/passkey.php, login_passkey.php) - once the database has them
|
||||
$config_login_passkeys = intval($row['config_login_passkeys'] ?? 0);
|
||||
|
||||
// The public help center link, once the database has the Knowledge Base settings (functions/kb.php)
|
||||
if (isset($row['config_module_enable_kb'], $row['config_kb_public_enable'])) {
|
||||
$config_module_enable_kb = intval($row['config_module_enable_kb']);
|
||||
@@ -142,13 +145,15 @@ function pendingExpired($sess, $ttl_seconds = 120) {
|
||||
}
|
||||
|
||||
// POST handling
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_POST['role_choice']) || isset($_POST['mfa_login']))) {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_POST['role_choice']) || isset($_POST['mfa_login']) || isset($_POST['passkey_login']))) {
|
||||
|
||||
$role_choice = $_POST['role_choice'] ?? null;
|
||||
|
||||
$is_login_step = isset($_POST['login']);
|
||||
$is_role_step = isset($_POST['role_choice']) && !$is_login_step && !isset($_POST['mfa_login']);
|
||||
$is_mfa_step = isset($_POST['mfa_login']);
|
||||
// After login_passkey.php checked a passkey - which counts as two-step sign-in
|
||||
$is_passkey_step = isset($_POST['passkey_login']) && !$is_login_step && !$is_mfa_step && !$is_role_step;
|
||||
|
||||
// -----------------------------------
|
||||
// STEP 2: ROLE CHOICE (no email/pass)
|
||||
@@ -194,6 +199,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// A PASSKEY, checked by login_passkey.php (no email/pass)
|
||||
// -----------------------------------
|
||||
if ($is_passkey_step && empty($response)) {
|
||||
|
||||
$posted_token = $_POST['pending_passkey_token'] ?? '';
|
||||
$sess = $_SESSION['pending_passkey_login'] ?? null;
|
||||
|
||||
if (pendingExpired($sess) || empty($posted_token) || empty($sess['token']) || !hash_equals($sess['token'], $posted_token)) {
|
||||
unset($_SESSION['pending_passkey_login']);
|
||||
header("HTTP/1.1 401 Unauthorized");
|
||||
$response = "
|
||||
<div class='alert alert-danger'>
|
||||
Your passkey sign in expired. Please sign in again.
|
||||
</div>";
|
||||
} else {
|
||||
$email = escapeSql($sess['email'] ?? '');
|
||||
$email_raw = (string) ($sess['email'] ?? '');
|
||||
$role_choice = ($sess['type'] ?? 'agent') === 'client' ? 'client' : 'agent';
|
||||
$passkey_name = escapeSql(mb_substr((string) ($sess['passkey_name'] ?? 'Passkey'), 0, PASSKEY_NAME_MAX));
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// STEP 1: INITIAL CREDENTIALS
|
||||
// -----------------------------------
|
||||
@@ -246,9 +274,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
$allowed_client_id = isset($sess['client_user_id']) ? intval($sess['client_user_id']) : null;
|
||||
}
|
||||
|
||||
if ($is_mfa_step) {
|
||||
$sess = $_SESSION['pending_mfa_login'] ?? null;
|
||||
// Only the account whose password was checked - the other kind is left out altogether (-1 matches no one)
|
||||
if ($is_mfa_step || $is_passkey_step) {
|
||||
$sess = $_SESSION[$is_passkey_step ? 'pending_passkey_login' : 'pending_mfa_login'] ?? null;
|
||||
// Only the account whose password (or passkey) was checked - the other kind is left out altogether (-1 matches no one)
|
||||
if (($sess['type'] ?? 'agent') === 'client') {
|
||||
$allowed_client_id = intval($sess['client_user_id'] ?? 0);
|
||||
$allowed_agent_id = -1;
|
||||
@@ -442,6 +470,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
$extended_log = 'with MFA';
|
||||
}
|
||||
|
||||
// A passkey is two-step sign-in in itself - the device, unlocked with their PIN, fingerprint or face
|
||||
if ($is_passkey_step) {
|
||||
$mfa_is_complete = true;
|
||||
$extended_log = "with a passkey ($passkey_name)";
|
||||
}
|
||||
|
||||
if ($mfa_is_complete) {
|
||||
|
||||
// Remember me token creation
|
||||
@@ -495,24 +529,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
$_SESSION['logged'] = true;
|
||||
// A later password change ends this session (userSessionStamp())
|
||||
$_SESSION['user_session_stamp'] = userSessionStamp($selectedRow['user_password'] ?? '');
|
||||
// A passkey sign-in is two-step already - MFA enforcement leaves it be (includes/load_user_session.php)
|
||||
$_SESSION['signed_in_with'] = $is_passkey_step ? 'passkey' : 'password';
|
||||
|
||||
if ($force_mfa == 1 && $token == NULL) {
|
||||
$mfa_to_set_up = $force_mfa == 1 && $token == NULL && !$is_passkey_step;
|
||||
if ($mfa_to_set_up) {
|
||||
$config_start_page = "user/mfa_enforcement.php";
|
||||
}
|
||||
|
||||
// The vault session WITHOUT PASSWORD IN SESSION - opened at step 1, while the password was here (vaultSignIn()).
|
||||
// After the role choice or two-step code it is already there; signing straight in, it is opened now.
|
||||
if (!$is_mfa_step && !$is_role_step) {
|
||||
// With a passkey it was opened by login_passkey.php, when the passkey could - or is unlocked later (vaultUnlock()).
|
||||
if (!$is_mfa_step && !$is_role_step && !$is_passkey_step) {
|
||||
vaultSignIn($user_id, $user_encryption_ciphertext, $password);
|
||||
}
|
||||
|
||||
// NOW safe to clear pending sessions AFTER we used them
|
||||
unset($_SESSION['pending_mfa_login']);
|
||||
unset($_SESSION['pending_dual_login']);
|
||||
unset($_SESSION['pending_passkey_login']);
|
||||
|
||||
// A new install's first admin is walked through what is left to set up, once (functions/getting_started.php) -
|
||||
// after MFA enforcement, and not instead of a page they were on their way to
|
||||
if (!($force_mfa == 1 && $token == NULL) && !isset($_GET['last_visited']) && gettingStartedFirstVisit($user_id)) {
|
||||
if (!$mfa_to_set_up && !isset($_GET['last_visited']) && gettingStartedFirstVisit($user_id)) {
|
||||
redirect('admin/getting_started.php');
|
||||
}
|
||||
|
||||
@@ -616,8 +655,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
// a remembered browser, or a code from their app. Wrong codes are
|
||||
// counted per account, as an agent's are.
|
||||
$client_mfa_secret = trim((string) ($selectedRow['user_token'] ?? ''));
|
||||
$client_mfa_done = $client_mfa_secret === '';
|
||||
$client_mfa_how = '';
|
||||
// A passkey is two-step sign-in in itself
|
||||
$client_mfa_done = $client_mfa_secret === '' || $is_passkey_step;
|
||||
$client_mfa_how = $is_passkey_step ? " with a passkey ($passkey_name)" : '';
|
||||
$client_mfa_locked = false;
|
||||
$client_code = preg_replace('/\s+/', '', (string) ($_POST['current_code'] ?? ''));
|
||||
if (!preg_match('/^[0-9]{6}$/', $client_code)) {
|
||||
@@ -693,6 +733,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
$_SESSION['user_type'] = 2;
|
||||
$_SESSION['contact_id'] = $contact_id;
|
||||
$_SESSION['login_method'] = "local";
|
||||
$_SESSION['signed_in_with'] = $is_passkey_step ? 'passkey' : 'password';
|
||||
// A later password change ends this session (userSessionStamp())
|
||||
$_SESSION['user_session_stamp'] = userSessionStamp($selectedRow['user_password'] ?? '');
|
||||
|
||||
@@ -708,6 +749,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_
|
||||
// and the vault a dual-role user's password opened, as they went on as the client
|
||||
unset($_SESSION['pending_dual_login']);
|
||||
unset($_SESSION['pending_mfa_login']);
|
||||
unset($_SESSION['pending_passkey_login']);
|
||||
unset($_SESSION['portal_view_as']);
|
||||
unset($_SESSION['user_encryption_session_ciphertext'], $_SESSION['user_encryption_session_iv']);
|
||||
|
||||
@@ -824,6 +866,7 @@ $show_login_form = (!$show_role_choice && !$show_mfa_form);
|
||||
placeholder="<?php if ($config_login_key_required) { if (!isset($_GET['key']) || $_GET['key'] !== $config_login_key_secret) { echo "Client "; } } echo "Email"; ?>"
|
||||
name="email"
|
||||
value="<?= htmlspecialchars($email ?? '', ENT_QUOTES) ?>"
|
||||
<?= $config_login_passkeys === 1 ? 'autocomplete="username webauthn"' : 'autocomplete="username"' ?>
|
||||
required autofocus
|
||||
>
|
||||
<div class="input-group-text">
|
||||
@@ -877,6 +920,23 @@ $show_login_form = (!$show_role_choice && !$show_mfa_form);
|
||||
|
||||
</form>
|
||||
|
||||
<?php if ($show_login_form && $config_login_passkeys === 1) { ?>
|
||||
<!-- Sign in with a passkey (js/passkey.js, login_passkey.php) - shown once the browser is known to do passkeys -->
|
||||
<div data-passkey-sign-in data-endpoint="login_passkey.php" hidden>
|
||||
<div class="d-flex align-items-center gap-2 mb-3 small text-body-secondary">
|
||||
<hr class="flex-grow-1 my-0"><span>or</span><hr class="flex-grow-1 my-0">
|
||||
</div>
|
||||
<div data-passkey-message></div>
|
||||
<button type="button" class="btn btn-outline-primary w-100 mb-3" data-passkey-button>
|
||||
<i class="fas fa-fingerprint me-2"></i>Sign in with a passkey
|
||||
</button>
|
||||
<form method="post" data-passkey-form>
|
||||
<input type="hidden" name="passkey_login" value="1">
|
||||
<input type="hidden" name="pending_passkey_token" value="">
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if($config_client_portal_enable == 1){ ?>
|
||||
<hr>
|
||||
<div class="d-flex flex-wrap justify-content-between gap-2">
|
||||
@@ -918,6 +978,9 @@ if (!$config_whitelabel_enabled) {
|
||||
<script src="<?= staticFileUrl('/libs/adminlte/js/adminlte.min.js') ?>"></script>
|
||||
<script src="<?= staticFileUrl('/js/login_prevent_resubmit.js') ?>"></script>
|
||||
<script src="<?= staticFileUrl('/js/otp_input.js') ?>"></script>
|
||||
<?php if ($show_login_form && $config_login_passkeys === 1) { ?>
|
||||
<script src="<?= staticFileUrl('/js/passkey.js') ?>"></script>
|
||||
<?php } ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user