Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- fix: iCloud clean up with `--keep-icloud-recent-days` does not respect `--skip-*` params [#1180](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1180)
- chore: replace build & test platform from retired windows-2019 to windows-2025
- Service Temporary Unavailable responses are less ambiguous [#1078](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1078)
- feat: re-authenticate on errors when using `--watch-with-interval` [#1078](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1078)
- feat: use stored cookies before attempting to authenticate with credentials

## 1.28.1 (2025-06-08)

Expand Down
50 changes: 27 additions & 23 deletions src/icloudpd/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import logging
import sys
import time
from typing import Callable, Dict, Tuple
from functools import partial
from typing import Callable, Dict, List, Tuple

import click

Expand Down Expand Up @@ -38,34 +39,37 @@ def authenticator(
) -> PyiCloudService:
"""Authenticate with iCloud username and password"""
logger.debug("Authenticating...")
icloud: PyiCloudService | None = None
_valid_password: str | None = None
for _, _pair in password_providers.items():
_reader, _ = _pair
_password = _reader(username)
if _password:
icloud = PyiCloudService(
filename_cleaner,
lp_filename_generator,
domain,
raw_policy,
file_match_policy,
username,
_password,
cookie_directory=cookie_directory,
client_id=client_id,
)
_valid_password = _password
break
valid_password: List[str] = []

def password_provider(username: str, valid_password: List[str]) -> str | None:
for _, _pair in password_providers.items():
reader, _ = _pair
password = reader(username)
if password:
valid_password.append(password)
return password
return None

icloud = PyiCloudService(
filename_cleaner,
lp_filename_generator,
domain,
raw_policy,
file_match_policy,
username,
partial(password_provider, username, valid_password),
cookie_directory=cookie_directory,
client_id=client_id,
)

if not icloud:
raise NotImplementedError("None of providers gave password")

if _valid_password:
if valid_password:
# save valid password to all providers
for _, _pair in password_providers.items():
_, _writer = _pair
_writer(username, _valid_password)
_, writer = _pair
writer(username, valid_password[0])

if icloud.requires_2fa:
if raise_error_on_2sa:
Expand Down
Loading
Loading