Skip to content

Commit c210886

Browse files
use token first for auth and support re-auth with watch (#1185)
1 parent d5f2205 commit c210886

File tree

8 files changed

+385
-298
lines changed

8 files changed

+385
-298
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- 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)
77
- chore: replace build & test platform from retired windows-2019 to windows-2025
88
- Service Temporary Unavailable responses are less ambiguous [#1078](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1078)
9+
- feat: re-authenticate on errors when using `--watch-with-interval` [#1078](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1078)
10+
- feat: use stored cookies before attempting to authenticate with credentials
911

1012
## 1.28.1 (2025-06-08)
1113

src/icloudpd/authentication.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import logging
44
import sys
55
import time
6-
from typing import Callable, Dict, Tuple
6+
from functools import partial
7+
from typing import Callable, Dict, List, Tuple
78

89
import click
910

@@ -38,34 +39,37 @@ def authenticator(
3839
) -> PyiCloudService:
3940
"""Authenticate with iCloud username and password"""
4041
logger.debug("Authenticating...")
41-
icloud: PyiCloudService | None = None
42-
_valid_password: str | None = None
43-
for _, _pair in password_providers.items():
44-
_reader, _ = _pair
45-
_password = _reader(username)
46-
if _password:
47-
icloud = PyiCloudService(
48-
filename_cleaner,
49-
lp_filename_generator,
50-
domain,
51-
raw_policy,
52-
file_match_policy,
53-
username,
54-
_password,
55-
cookie_directory=cookie_directory,
56-
client_id=client_id,
57-
)
58-
_valid_password = _password
59-
break
42+
valid_password: List[str] = []
43+
44+
def password_provider(username: str, valid_password: List[str]) -> str | None:
45+
for _, _pair in password_providers.items():
46+
reader, _ = _pair
47+
password = reader(username)
48+
if password:
49+
valid_password.append(password)
50+
return password
51+
return None
52+
53+
icloud = PyiCloudService(
54+
filename_cleaner,
55+
lp_filename_generator,
56+
domain,
57+
raw_policy,
58+
file_match_policy,
59+
username,
60+
partial(password_provider, username, valid_password),
61+
cookie_directory=cookie_directory,
62+
client_id=client_id,
63+
)
6064

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

64-
if _valid_password:
68+
if valid_password:
6569
# save valid password to all providers
6670
for _, _pair in password_providers.items():
67-
_, _writer = _pair
68-
_writer(username, _valid_password)
71+
_, writer = _pair
72+
writer(username, valid_password[0])
6973

7074
if icloud.requires_2fa:
7175
if raise_error_on_2sa:

0 commit comments

Comments
 (0)