TOTP 2FA, App passwords and account disable support (closes #436 closes #479)

This commit is contained in:
mdecimus
2024-06-28 12:12:51 +02:00
parent 0693253dff
commit d8a73cd0e4
30 changed files with 250 additions and 85 deletions

View File

@@ -23,7 +23,7 @@ parking_lot = "0.12"
tracing = "0.1"
ahash = { version = "0.8" }
md5 = "0.7.0"
dashmap = "5.4"
dashmap = "6.0"
rand = "0.8.5"
[features]

View File

@@ -101,6 +101,7 @@ impl<T: SessionStream> Session<T> {
}
// Authenticate
let mut is_totp_error = false;
let access_token = match credentials {
Credentials::Plain { username, secret } | Credentials::XOauth2 { username, secret } => {
match self
@@ -110,6 +111,10 @@ impl<T: SessionStream> Session<T> {
{
AuthResult::Success(token) => Some(token),
AuthResult::Failure => None,
AuthResult::MissingTotp => {
is_totp_error = true;
None
}
AuthResult::Banned => return Err(()),
}
}
@@ -174,10 +179,14 @@ impl<T: SessionStream> Session<T> {
Ok(())
} else {
self.write_bytes(
StatusResponse::no("Authentication failed")
.with_tag(tag)
.with_code(ResponseCode::AuthenticationFailed)
.into_bytes(),
StatusResponse::no(if is_totp_error {
"Missing TOTP code, try with 'secret$totp_code'."
} else {
"Authentication failed."
})
.with_tag(tag)
.with_code(ResponseCode::AuthenticationFailed)
.into_bytes(),
)
.await?;