Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Sign-in: show why Apple refused the password proof from that step's own reply (a locked account, -20209), and that an app-specific password can't sign in

Yashwanth Kamireddi7ef9c9beb2a7
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rs
index dd305ff..7900f95 100644
--- a/crates/quince-auth/src/lib.rs
+++ b/crates/quince-auth/src/lib.rs
@@ -92,8 +92,10 @@ const UA: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/53
#[derive(Debug, thiserror::Error)]
pub enum Error {
- #[error("That Apple Account or password wasn't accepted.")]
+ #[error("Apple didn't accept that Apple Account or password. Use your Apple Account password itself: an app-specific password can't sign in here.")]
BadCredentials,
+ #[error("Apple has locked this Apple Account for security. Unlock it at iforgot.apple.com, then sign in here again.")]
+ AccountLocked,
#[error("That code didn't match. Check your iPhone and try again.")]
BadCode,
#[error("Apple didn't return a trust token, so this session wouldn't survive a restart")]
@@ -166,6 +168,10 @@ fn apple_error(context: &str, status: StatusCode, body: &str) -> Error {
if code == "-21669" {
return Error::BadCode;
}
+ // -20209 is Apple's "locked for security reasons", most often after many tries.
+ if code == "-20209" {
+ return Error::AccountLocked;
+ }
if message.to_ascii_lowercase().contains("too many") {
return Error::RateLimited;
}
@@ -941,6 +947,13 @@ impl Client {
.await?;
self.capture(&r);
let status = r.status();
+ // This step's own reply: its serviceErrors say why Apple refused (a locked account,
+ // a wrong password). The challenge from /signin/init is not the reason and is never shown.
+ let text = if status.is_success() || status == StatusCode::CONFLICT {
+ String::new()
+ } else {
+ r.text().await.unwrap_or_default()
+ };
match status {
StatusCode::CONFLICT => {
@@ -1691,6 +1704,20 @@ mod tests {
);
}
+ #[test]
+ fn a_locked_account_and_a_wrong_password_read_as_what_they_are() {
+ let words = Error::BadCredentials.to_string();
+ assert!(words.contains("app-specific"), "{words}");
+ let locked = r#"{"serviceErrors":[{"code":"-20209","message":"This Apple Account has been locked for security reasons."}]}"#;
+ assert!(matches!(
+ apple_error("finishing sign-in", StatusCode::FORBIDDEN, locked),
+ Error::AccountLocked
+ ));
+ assert!(Error::AccountLocked
+ .to_string()
+ .contains("iforgot.apple.com"));
+ }
+
#[test]
fn apple_errors_are_classified() {
let wrong =
diff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rs
index 1fac3a0..e14e181 100644
--- a/crates/quince-auth/tests/auth_flow.rs
+++ b/crates/quince-auth/tests/auth_flow.rs
@@ -987,3 +987,32 @@ async fn a_store_that_will_not_keep_the_session_never_fails_the_sign_in() {
assert!(client.unsaved().is_none());
assert!(client_for(&server, dir.path()).has_stored_session());
}
+
+/// A locked account is also a 403 from `/signin/complete`, with Apple's code -20209. It must
+/// say the account is locked and where to unlock it, never that the password was wrong.
+#[tokio::test]
+async fn a_locked_account_says_so_not_wrong_password() {
+ let server = MockServer::start().await;
+ mount_init(&server, 200).await;
+ Mock::given(method("POST"))
+ .and(path("/appleauth/auth/signin/complete"))
+ .respond_with(ResponseTemplate::new(403).set_body_json(json!({
+ "serviceErrors": [{
+ "code": "-20209",
+ "message": "This Apple Account has been locked for security reasons."
+ }]
+ })))
+ .mount(&server)
+ .await;
+ let dir = tempfile::tempdir().unwrap();
+ let mut client = client_for(&server, dir.path());
+ let err = client
+ .sign_in("[email protected]", "pw")
+ .await
+ .unwrap_err();
+ assert!(
+ matches!(err, quince_auth::Error::AccountLocked),
+ "got {err:?}"
+ );
+ assert!(err.to_string().contains("iforgot.apple.com"), "{err}");
+}