Fix identity provider gaps: a required provider is decided before any password or mail password is checked and the sign-in page says the same whatever was typed, account or not; required beats IMAP on the same domain; after five wrong passwords for an address in ten minutes its mail server isn't asked; Google signs in only Workspace accounts and Nextcloud has to say the address is verified; client secrets are sealed with the install key, with RMM's sealing moved to shared secretSeal and secretOpen; an IMAP server is tried when saved or turned on and Required waits for a first sign-in; joining, Forgot password, password links and welcome emails follow mail-password and required domains; Turn Off says who goes back to a password; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-30 01:36:20 -05:00
parent 8ce7ad0789
commit adbd8866c2
18 changed files with 499 additions and 142 deletions

View File

@@ -4,7 +4,9 @@
* started > Your team): ?invite=&token=. The person checks their name and
* chooses a password - nobody else ever knows it - and is made an agent with
* the role, MFA and client access the invite set (userInviteAccept(),
* functions/user_invite.php). Then they sign in on the usual page. A link
* functions/user_invite.php). Then they sign in on the usual page - or, where
* their email domain's mail server checks passwords (IMAP) or a provider is
* required for it, that way, the password only opening their credentials. A link
* that has run out, been used or cancelled says so, and what to do instead.
*
* The client portal's own invites open client/join.php.
@@ -66,6 +68,15 @@ if ($invite && in_array($link['state'], ['pending', 'accepted'], true) && !empty
$sign_in .= '?key=' . rawurlencode((string) $config_login_key_secret);
}
// How they sign in - their email domain's mail server may check the password (IMAP), or a provider be required
// for it (functions/identity_provider.php). The password chosen here still opens their credentials either way
$password_use = $invite ? identityProviderPasswordUse($invite['invite_email'], 1, intval($invite['invite_role_id'] ?? 0)) : ['use' => 'password', 'name' => ''];
$sign_in_how = [
'provider' => 'Sign in with ' . $password_use['name'] . ' - its button on the sign-in page.',
'mail' => 'Sign in with ' . ($invite['invite_email'] ?? 'your email address') . ' and your email password - the one for your mailbox.',
'password' => 'Sign in with ' . ($invite['invite_email'] ?? 'your email address') . ' and your new password.',
][$password_use['use']];
if ($invite && $link['state'] === 'pending' && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['agent_join'])) {
$in_name = (string) ($_POST['name'] ?? '');
$user_id = userInviteAccept($invite, $token, [
@@ -75,8 +86,9 @@ if ($invite && $link['state'] === 'pending' && $_SERVER['REQUEST_METHOD'] === 'P
], $error);
if ($user_id) {
$first = strtok(trim(preg_replace('/\s+/', ' ', strip_tags($in_name))), ' ');
$_SESSION['login_message'] = "Welcome, $first - your account is ready. Sign in with " . $invite['invite_email'] . ' and your new password.'
. (intval($invite['invite_force_mfa']) ? ' Have your authenticator app ready - you set up multi-factor authentication as you sign in.' : '');
$_SESSION['login_message'] = "Welcome, $first - your account is ready. $sign_in_how"
. ($password_use['use'] !== 'password' ? ' The password you chose opens your credentials - you are asked for it the first time you open one.' : '')
. (intval($invite['invite_force_mfa']) && $password_use['use'] !== 'provider' ? ' Have your authenticator app ready - you set up multi-factor authentication as you sign in.' : '');
$_SESSION['login_message_type'] = 'success';
header("Location: $sign_in");
exit();
@@ -91,7 +103,7 @@ $ask = $by !== '' ? "Ask $by to send it again." : 'Ask your administrator to sen
$notes = [
'gone' => ["That link doesn't work", 'It may have been copied only in part - or a newer invite replaced it, so use the link in the latest one.'],
'expired' => ['That invite has run out', 'Invites work for ' . USER_INVITE_LINK_DAYS . " days. $ask"],
'accepted' => ["You've joined already", 'Sign in with ' . ($invite['invite_email'] ?? 'your email address') . ' and the password you chose.'],
'accepted' => ["You've joined already", $password_use['use'] === 'password' ? 'Sign in with ' . ($invite['invite_email'] ?? 'your email address') . ' and the password you chose.' : $sign_in_how],
'cancelled' => ['That invite was cancelled', $by !== '' ? "Ask $by about it." : 'Ask your administrator about it.'],
];
$state = $link['state'];
@@ -130,7 +142,13 @@ $title = $state === 'pending' ? "Join $where" : $notes[$state][0];
<h1 class="h5 mb-1" data-join="agent"><?= escapeHtml($title) ?></h1>
<p class="text-body-secondary small mb-3">
<?= $by !== '' ? escapeHtml($by) . ' invited' : 'You are invited as' ?> <strong><?= escapeHtml($invite['invite_email']) ?></strong> to join <?= escapeHtml($where) ?><?php if ((string) $invite['role_name'] !== '') { ?>, as <strong><?= escapeHtml($invite['role_name']) ?></strong><?php } ?>.
Choose your password and you're ready to sign in.
<?php if ($password_use['use'] === 'provider') { ?>
You sign in with <?= escapeHtml($password_use['name']) ?> - choose a password for opening your credentials.
<?php } elseif ($password_use['use'] === 'mail') { ?>
You sign in with your email password - choose a password for opening your credentials.
<?php } else { ?>
Choose your password and you're ready to sign in.
<?php } ?>
</p>
<?php if ($error !== '') { ?>
@@ -158,9 +176,13 @@ $title = $state === 'pending' ? "Join $where" : $notes[$state][0];
<span class="input-group-text"><i class="fas fa-fw fa-check-double"></i></span>
<input type="password" class="form-control" name="confirm_password" minlength="<?= USER_PASSWORD_MIN ?>" autocomplete="new-password" placeholder="The same again" aria-label="The password again" required>
</div>
<p class="small text-body-secondary mb-3"><i class="fas fa-fw fa-key me-1"></i>It also unlocks the credential vault for you, so keep it to yourself.</p>
<?php if ($password_use['use'] === 'password') { ?>
<p class="small text-body-secondary mb-3"><i class="fas fa-fw fa-key me-1"></i>It also unlocks the credential vault for you, so keep it to yourself.</p>
<?php } else { ?>
<p class="small text-body-secondary mb-3" data-join-password-use="<?= $password_use['use'] ?>"><i class="fas fa-fw fa-key me-1"></i><?= $password_use['use'] === 'provider' ? 'Accounts on ' . escapeHtml(identityProviderEmailDomain($invite['invite_email'])) . ' sign in with ' . escapeHtml($password_use['name']) . ' here, not a password' : 'Your mail server checks the password you sign in with' ?> - this one unlocks the credential vault for you: you're asked for it the first time you open a credential. Keep it to yourself.</p>
<?php } ?>
<?php if (intval($invite['invite_force_mfa'])) { ?>
<?php if (intval($invite['invite_force_mfa']) && $password_use['use'] !== 'provider') { ?>
<div class="alert alert-info small d-flex gap-2" data-join-mfa>
<i class="fas fa-mobile-alt mt-1"></i>
<div>Multi-factor authentication is required: have an authenticator app on your phone ready - you set it up as you sign in.</div>