jeffreydwalter / arlo

Python module for interacting with Netgear's Arlo camera system.
Apache License 2.0
520 stars 123 forks source link

email factorRole SECONDARY throws StopIteration #194

Open scubar opened 2 years ago

scubar commented 2 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Python are you using (python -V)?

Python 3.10.4

What operating system and processor architecture are you using (python -c 'import platform; print(platform.uname());')?

uname_result(system='Linux', node='DESKTOP-45GVB31', release='4.4.0-19041-Microsoft', version='#1237-Microsoft Sat Sep 11 14:32:00 PST 2021', machine='x86_64')

Which Python packages do you have installed (run the pip freeze or pip3 freeze command and paste output)?

arlo==1.2.59
attrs==22.1.0
cachetools==5.2.0
certifi==2022.6.15
charset-normalizer==2.1.0
google-api-core==2.8.2
google-api-python-client==2.57.0
google-auth==2.10.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.5.2
googleapis-common-protos==1.56.4
httplib2==0.20.4
idna==3.3
iniconfig==1.1.1
monotonic==1.6
oauthlib==3.2.0
packaging==21.3
pickle-mixin==1.0.2
pluggy==1.0.0
protobuf==4.21.5
py==1.11.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==3.0.9
PySocks==1.7.1
pytest==7.1.2
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.9
six==1.16.0
sseclient==0.0.22
tomli==2.0.1
uritemplate==4.1.1
urllib3==1.24

Which version of ffmpeg are you using (ffmpeg -version)?

ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

Which Arlo hardware do you have (camera types - [Arlo, Pro, Q, etc.], basestation model, etc.)?

Arlo Pro 2

VMB4000 Base Station

What did you do?

Note: I was able to resolve this issue by making a change within Arlo.py. This issue may affect other users as well so I wanted to report it.

My factors body has my email factorRole as "SECONDARY" but by default it would only be matched if it was "PRIMARY".

This was causing StopIteration to be thrown. Here's what my factors_body looks like:

    "meta": {
        "code": 200
    },
    "data": {
        "_type": "_Collection",
        "items": [
            {
                "_type": "SecondFactor",
                "factorId": "x",
                "factorType": "PUSH",
                "displayName": "iPhone13,3",
                "factorNickname": "iPhone 12 Pro",
                "applicationId": "x",
                "applicationName": "Arlo",
                "factorRole": "SECONDARY"
            },
            {
                "_type": "SecondFactor",
                "factorId": "x",
                "factorType": "PUSH",
                "displayName": "iPhone13,3",
                "factorNickname": "iPhone 12",
                "applicationId": "x",
                "applicationName": "Arlo",
                "factorRole": "PRIMARY"
            },
            {
                "_type": "SecondFactor",
                "factorId": "x",
                "factorType": "EMAIL",
                "displayName": "x@x.com",
                "factorNickname": "x@x.com",
                "applicationId": "x",
                "applicationName": "Generic",
                "factorRole": "SECONDARY"
            },
            {
                "_type": "SecondFactor",
                "factorId": "x",
                "factorType": "PUSH",
                "displayName": "iPad12,2",
                "factorNickname": "x's iPad",
                "applicationId": "x",
                "applicationName": "Arlo",
                "factorRole": "SECONDARY"
            }
        ],
        "MFA_State": "ENABLED"
    }
}

I simply changed line 222 in Arlo.py as of commit a8e74384f235e6e694c8713c172fd30bdb57fd7a to:

        email_factor_id = next(i for i in factors_body['data']['items'] if i['factorType'] == 'EMAIL' and i['factorRole'] == "SECONDARY")['factorId']

Does this issue reproduce with the latest release?

Yes

jeffreydwalter commented 2 years ago

Would you mind creating a PR for this? Thank you!

scubar commented 2 years ago

Would you mind creating a PR for this? Thank you!

Sure I can file one, just wasn't sure about the best way to handle this. I'm not sure if my factors_body is unique or if its possible to have multiple email factors etc.

Would we want to possibly add an argument to the Arlo class init that would allow them to specify the email address to use for 2FA and then iterate through the factorNickname of each email factor with it?

jeffreydwalter commented 2 years ago

Hey! Sorry, for the long delay. I have had a busy life lately... I would be ok with adding an argument to init. That seems reasonable.

jeffreydwalter commented 2 years ago

I went ahead and pushed a fix for your issue. Give https://github.com/jeffreydwalter/arlo/releases/tag/1.2.62 a try.

Please close this issue if it works. If not, leave me a comment. Thanks!