icloud-photos-downloader / icloud_photos_downloader

A command-line tool to download photos from iCloud
MIT License
6.23k stars 529 forks source link

adding notifications stops the script before entering 2FA #685

Open brunoamaral opened 10 months ago

brunoamaral commented 10 months ago

Overview

Adding notifications with smtp stops the script after entering a password and before we have time to enter de 2FA.

Steps to Reproduce

sudo docker run -it --rm --name icloudpd -v /mnt/Photos/originals:/data -e TZ=Europe/Lisbon icloudpd/icloudpd:latest icloudpd --until-found 200 --directory /data --username USER@ICLOUD.com --watch-with-interval 1800 --smtp-host smtp.eu.mailgun.org --notification-email XXXXX@XXXXXX --smtp-username XXXXX@XXXXX --smtp-password PASSWORD

Expected Behavior

Wait for the user to input the 2FA before proceeding

Actual Behavior

2023-09-11 17:50:50 DEBUG    Authenticating...
iCloud Password:
2023-09-11 17:50:55 INFO     Sending 'two-step expired' notification via email...
2023-09-11 17:50:55 INFO     Sending 'two-step expired' notification via email...
script exits

Context

ppfeister commented 6 months ago

Experiencing this issue as well. Pretty odd. Also testing with mailgun.

Experimenting with this compose file:

services:
    icloudpd:
        stdin_open: true
        tty: true
        container_name: icloudpd
        volumes:
            - /data:/data
        environment:
            - TZ=America/New_York
        image: icloudpd/icloudpd:latest
        command: >
            icloudpd
            --directory /data
            --username [ . . . ]
            --watch-with-interval 3600
            --auto-delete
            --smtp-username [ . . . ]
            --smtp-password [ . . . ]
            --smtp-port 587
            --smtp-host smtp.mailgun.org
            --notification-email [ . . . ]
            --notification-email-from [ . . . ]
o42o commented 5 months ago

Same issue here on Docker.

This worked well without notification :

docker run -it --rm --name icloudpd -v /_redacted_/Photos:/data -e TZ=America/Toronto icloudpd/icloudpd:latest icloudpd --directory /data --username _redacted_ --watch-with-interval 86400 --log-level info

iCloud Password: 
2024-02-01 22:47:29 INFO     Two-step/two-factor authentication is required (2fa)
Please enter two-factor authentication code: _redacted_
2024-02-01 22:47:48 WARNING  Failed to parse response with JSON mimetype
2024-02-01 22:47:50 INFO     Great, you're all set up. The script can now be run without user interaction until 2SA expires.
You can set up email notifications for when the two-step authentication expires.
(Use --help to view information about SMTP options.)
2024-02-01 22:47:53 INFO     Downloading 7656 original photos and videos to /data ...
2024-02-01 22:51:12 INFO     All photos have been downloaded
2024-02-01 22:51:12 INFO     Waiting for 86400 sec...

This one did not worked with notification :

docker run -it --rm --name icloudpd -v /_redacted_/Photos:/data -e TZ=America/Toronto icloudpd/icloudpd:latest icloudpd --directory /data --username _redacted_ --watch-with-interval 86400 --smtp-username _redacted_ --smtp-password _redacted_ --smtp-host smtp.sendgrid.net --notification-email _redacted_ --notification-email-from _redacted_

2024-02-01 22:45:50 DEBUG    Authenticating...
iCloud Password: 
2024-02-01 22:46:03 INFO     Sending 'two-step expired' notification via email...

Also, is there any way in Docker to save password and MFA when the container is restarted?

Thank you!

AndreyNikiforov commented 1 month ago

The behavior to exit if notification is requested, has been in the code base for some time (==not a recent change).

What is the use case for email notification? If 2fa is required, then Apple is showing alert on a relevant device without extra action from icloudpd, so user is notified. I assume that 2fa request has some expiration, so if user has not responded to alert, authentication needs to start all over. From that perspective, makes sense to exit when sending notification with expected long response time (email response is presumably slower than alert on a device). I do not know if Apple behavior for 2fa alerts were different when email notification for icloudpd was implemented.